I have tried to set target audience property with the lines code:
#Create client context
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl);
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Admin, (convertto-securestring $AdminPassword -asplaintext -force));
$ctx.ExecuteQuery();
#Get current web
$spoWeb = $ctx.Web
$ctx.Load($spoWeb)
$ctx.ExecuteQuery()
#Get task list
$tasklist = $ctx.Web.Lists.GetByTitle("ABCTasks")
$ctx.Load($tasklist)
$ctx.ExecuteQuery()
#Get hide view pages of the task
$taskpages = $tasklist.RootFolder.Files
$ctx.Load($taskpages)
$ctx.ExecuteQuery()
#Get view taskpages of the task list
foreach($taskpage in $taskpages){
#Write-Host $taskpage.Name
if($taskpage.Name -eq "ABCUserView.aspx"){
$ctx.Load($taskpage)
$ctx.ExecuteQuery()
break
}
}
#Get webpart manager from the task page
$wpm = $taskpage.GetLimitedWebPartManager("Shared")
$ctx.Load($wpm)
$ctx.ExecuteQuery()
#Get all of webpart of the task page
$webparts = $wpm.WebParts
$ctx.Load($webparts)
$ctx.ExecuteQuery()
#Get webpart and set target audience for the view
$webpart = $webparts[0]
$ctx.Load($webpart)
$ctx.ExecuteQuery()
$webpart.WebPart.Properties["AuthorizationFilter"] = "ABC User Group;;"
$webpart.SaveWebPartChanges();
$ctx.Load($webpart);
$ctx.ExecuteQuery();
After execute the lines code and open the ABCUserView.aspx page, this page is blank. The list view webpart doesn't display with the current user and users of ABC User Group was targeted and I don't know why.