我们是否可以在没有sharepoint powershell snapin的情况下更新sharepoint列表页面

时间:2017-11-21 09:28:24

标签: powershell sharepoint

我要求每周自动化,更新sharepoint列表页面。我可以使用powershell更新sharepoint列表页面吗?我没有权限访问sharepoint power shell snapins。

1 个答案:

答案 0 :(得分:0)

您可以使用powershell更新网站页面上的sharepoint网页部件,是的。不知道为什么你不能访问snapins但是?这是一个可以帮你完成工作的脚本:

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
Start-SPAssignment -Global
$Web = Get-SPWeb http://your/site/here
$Web.AllowUnsafeUpdates = $true

Try { 

    $CONTENT_TO_ADD_TO_PAGE = "New content"

    #Get the sitepage
    $file= $web.GetFile($web.Url +"/SitePages/YOURPAGE.aspx")
    if($file.Exists) {
        #Web Part Manager to get all web parts from the file
        $WebPartManager = $web.GetLimitedWebPartManager( $file,  [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

        #Iterate through each web part
        foreach($webPart in $WebPartManager.WebParts | Where {$_.title -eq "WEB PART NAME"}) {
                $XmlDoc = New-Object System.Xml.XmlDocument
                $contentXml=$xmlDoc.CreateElement("content") 
                $contentXml.InnerText= $CONTENT_TO_ADD_TO_PAGE
                #Set content and Save
                $webpart.Content = $contentXml    
                $webPartManager.SaveChanges($webPart);
        }   
    }

} Finally {
    Remove-Variable file, $WebPartManager
    $Web.AllowUnsafeUpdates = $false
    $Web.Dispose()
    Stop-SPAssignment -Global
    [GC]::Collect()
}