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();
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: