我要求每周自动化,更新sharepoint列表页面。我可以使用powershell更新sharepoint列表页面吗?我没有权限访问sharepoint power shell snapins。
答案 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()
}