我们可以在没有SharePoint PowerShell Snapin的情况下更新SharePoint列表页面



我有一个要求自动化的要求,每周更新SharePoint列表页面。我可以使用PowerShell更新SharePoint列表页面吗?我可以访问SharePoint Power Shell Snapins。

您可以在使用PowerShell的站点页面上更新SharePoint Web零件,是的。不知道为什么您无法访问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()
}

相关内容

最新更新