Tag Archives: web

WebPart Targeting with Powershell

WebPart Targeting with Powershell in SharePoint 2013

$web = Get-SPWeb "http://sharepoint/Page2";
$sharepointGroups = ';;Group1,Group2';
$webPath = "pages/yourpage.aspx";
$webPM = $web.GetLimitedWebPartManager($webPath, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared);
$webParts = $webPM.WebParts;
$myWebPart = $webParts | where { $_.Title -match "Web Part name" };
$myWebPart.AuthorizationFilter = [string]"$sharepointGroups";
$webPM.SaveChanges($myWebPart);
$web.Dispose();