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

时间:2014-02-21 22:44:02

标签: sharepoint powershell sharepoint-2010

我有特定SharePoint 2010页面的列表网址。我可以访问每个页面并单击“发布”按钮。然后批准按钮发布页面。

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

1 个答案:

答案 0 :(得分: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");
    }
}