This project is read-only.

Errors in Compile-SharePointAudience


In your Compile-SharePointAudience method, I found that you call RunAudienceJob with an improper argument. You provide the searchContext.Name, as you can see below:
    [Array]$args = $searchContext.Name, "1", "1", $AudienceName
    [int]$runjob = [Microsoft.Office.Server.Audience.AudienceJob]::RunAudienceJob($args)
However, as you can see from the msdn documentation, the first argument should be the "ApplicationID", which in this case refers to the User Profile Service Application's ID. Therefore, I think you can run the following code instead which has compiled audiences properly for me:
$upa = Get-SPServiceApplication | Where-Object {$_.DisplayName -eq "User Profile Service Application"}
$runjob = [Microsoft.Office.Server.Audience.AudienceJob]::RunAudienceJob(($upa.Id.Guid.ToString(), "1", "1", $AudienceName))