如何从PowerShell发布/批准SharePoint 2010中的页面

Sha*_*hed 9 powershell sharepoint sharepoint-2010

我有一个特定SharePoint 2010页面的列表URL.我可以访问每个页面并单击"发布"按钮.然后批准按钮发布页面.

我正在尝试自动化这个过程.我想知道PowerShell有没有办法做到这一点?

Lui*_*uis 14

下面的脚本应该这样做:

$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");
    }
}
Run Code Online (Sandbox Code Playgroud)