我想添加一个App-Web Part,就像自定义列表一样,它已经在使用Powershell的Sharepoint中。我怎么能这样做?
答案 0 :(得分:2)
这应该可以胜任......
$WebUrl = 'Your Site\Web Url'
Add-PSSnapin "Microsoft.SharePoint.Powershell"
$SPWeb = Get-SPWeb $WebUrl
$oWebPartPage = $SPWeb.GetFile("SitePages/Test.aspx") # Url of Page where webpart should be added
$oWebPartPage.Checkout()
$oWebPartManager = $oWebPartPage.GetLimitedWebPartManager([System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
$list = $SPWeb.Lists["YourListName"] # Name of the list
$oWebPartView = New-Object "Microsoft.SharePoint.WebPartPages.ListViewWebPart"
$oWebPartView.ListName = $list.ID.ToString("B").ToUpper()
$oWebPartView.ViewType = "None"
$oWebPartView.ViewGuid = ""
$oWebPartManager.AddWebPart($oWebPartView,"RightZone",2)
$oWebPartManager.SaveChanges($oWebPartView)