.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Approve Masterpages and Pagelayouts using powershel

Posted By:Ravishankar       Posted Date: April 25, 2011    Points: 200    Category: SharePoint    URL: http://www.dotnetspark.com  

Through this article, it will be easy to approve master pages and pagelayouts that you are going to upload. It will save the time of approving each item.
 

Through this article, it will be easy to approve master pages and pagelayouts that you are going to upload. It will save the time of approving each item.

#Add the Sharepoint powershell Snap In
#Call PowershellSnap in Function
Add-PSSnapin Microsoft.SharePoint.Powershell
Set-ExecutionPolicy RemoteSigned -ErrorAction SilentlyContinue -ErrorVariable excPolicyErr
$ExecutionPolicy = Get-ExecutionPolicy
if($excPolicyErr)
{
Write-Host "$excPolicyErr"
}
Write-Host "My 2010 Powershell Script"
$site = Get-SPSite -Identity "http://sharepointHome:2010"
$SPWeb = Get-SPWeb "http://sharepointHome:2010/"
$List = $SPWeb.Lists["Master Page Gallery"];
for($i=0;$i -le $List.Folders.count;$i++)
{
if(($List.Folders[$i].folder.name -eq "MyCustomMasterPage") -or ($List.Folders[$i].folder.name -eq "MyCustomPageLayouts"))
{
$univadisPagesFolder = $SPWeb.GetFolder($List.Folders[$i].Folder.Url);
$univadisPages = $univadisPagesFolder.Files;
foreach ($univadisPage in $univadisPages)
{
$lstItem = $univadisPage.Item;
if($lstItem.ModerationInformation)
{
if ($lstItem.ModerationInformation.Status -eq [Microsoft.SharePoint.SPModerationStatusType]::Pending)
{
$strStatus= [Microsoft.SharePoint.SPModerationStatusType]::Approved;
$lstItem.ModerationInformation.Status = $strStatus;
$lstItem.Update();
$univadisPage.Approve("Approved");
$univadisPage.Update();
Write-host "Approved:" $univadisPage.Name

}

}
}

}

}
$List.Update()

Save the file with extension .ps1 and call the file using a bat file.

 Subscribe to Articles

     

Further Readings:

    Responses

    No response found. Be the first to respond this post

    Post Comment

    You must Sign In To post reply
    Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

    Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend