如何使用Powershell将App-Web部件添加到页面中

时间:2015-03-04 12:24:40

标签: powershell sharepoint sharepoint-2013

我想添加一个App-Web Part,就像自定义列表一样,它已经在使用Powershell的Sharepoint中。我怎么能这样做?

1 个答案:

答案 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)