How To Get The Number Of Uncompiled Audiences In A User Profile Service Application Using PowerShell

If you are using Target Audience in your SharePoint environments, you must manage the Audiences in the Central Administration -> User Profile Service Application.

As a SharePoint administrator, you need to monitor the uncompiled audience every day. Here is the UI interface, where you can see the uncompiled audiences.

Go to Central Admin site- > Manage Service Application -> Open User Profile Service Application

 
To get the Uncompiled Audiences value, using PowerShell, the script is given below.

#put any site collection URL belongs to the User Profile Service application.

$objSite = Get-SPSite "http://sam.hr.com/sites/xyz";

$objContext=[Microsoft.Office.Server.ServerContext]::GetContext($objSite);

$objAudManager=New-Object Microsoft.Office.Server.Audience.AudienceManager($objContext);

#Total Audience minus(-) complied audience = Uncompiled Audience

$uncomiledAud = $objAudManager.Audiences.Count - $objAudManager.Audiences.AudienceCompiledSofar;

Write-Host "Number of Uncompiled Audience : " $uncomiledAud

You can copy the script given above and create a PS1 file(PFA). This will help you in designing a Task Scheduler to run once in a day and you can include the additional script to send an alert by email for the notification.

I hope it helps.