Export Members of a SharePoint Audience

Here is a quick PowerShell script that I put together for a customer to enable them to export the usernames and e-mail addresses of all users that are members of a specific SharePoint Audience to a CSV file.

Please update the three highlighted values, $Output is the location to write the CSV file to, replace http://intranet.contoso.com with the URL of a Site Collection that resides within a Web Application that is associated with the User Profile Service Application that contains the Audience and replace "Test" with the name of the Audience that you wish to export.

This script was tested on SharePoint 2010 but should also work on SharePoint 2013.

asnp *SharePoint* -ea 0
"Username"+","+"Email" | Out-File -Encoding Default -FilePath $Output;
$Site = Get-SPSite "http://intranet.contoso.com"
$AudManager=New-Object Microsoft.Office.Server.Audience.AudienceManager($Context)
$Audience=$AudManager.Audiences | Where {$_.AudienceName -eq "Test"}
Foreach ($Member in $Audience.GetMembership())
Write-Host $Member.NTName
Write-Host $Member.Email
$Member.NTName + "," + $Member.Email | Out-File -Encoding Default -Append -FilePath $Output

Brendan Griffin - @brendankarl