Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to publish/approve a page in SharePoint 2010 from powershell

I have a list urls for specific SharePoint 2010 pages. I can visit each page and click the publish button. Then approve button to publish the pages.

I am trying to automate the process. I am wondering if there is any way to do that from powershell?

like image 821
Shahed Avatar asked Feb 21 '14 22:02

Shahed


1 Answers

The script bellow should do it:

$web = Get-SPWeb http://demo2010a:20905
$pages = "http://demo2010a:20905/Pages/TvAndRadioAlerts.aspx","http://demo2010a:20905/Pages/Systems.aspx"
$pages | ForEach-Object {
$item = $web.GetListItem($_)
    if ($item.File.CheckOutType -ne "None")
    {
        $item.File.CheckIn("Automatically checked in by Powershell", "MajorCheckIn");
    }
    if ($item.Versions[0].Level -ne "Published")
    {
        $item.File.Publish("Automatically published by Powershell");
    }
    if ($item.ModerationInformation.Status -ne "Approved")
    {
        $item.File.Approve("Automatically approved by by Powershell");
    }
}
like image 56
Luis Avatar answered Oct 22 '22 09:10

Luis