I have multiple page containing web parts, I want to set a specific property, like Target Audiences, using powershell.
Is it possible?
Try using below code
$List = $context.Web.Lists.GetByTitle("ListName")
$context.Load($List)
$context.ExecuteQuery()
$Pages = $List.RootFolder.Files
$context.Load($Pages)
$context.ExecuteQuery()
$Page = $Pages | Where {$_.Name -eq "ViewName"}
$context.Load($Page)
$context.ExecuteQuery()
$WPM = $Page.GetLimitedWebPartManager("Shared")
$context.Load($WPM)
$context.ExecuteQuery()
$WebParts = $WPM.WebParts
$context.Load($WebParts)
$context.ExecuteQuery()
$WebPart = $WebParts[0]
$context.Load($WebPart)
$context.ExecuteQuery()
$WebPart.WebPart.Properties["AuthorizationFilter"] = "My Group"
$WebPart.SaveWebPartChanges();
$context.Load($WebPart);
$context.ExecuteQuery();
RefClick Here