Events
Microsoft 365 Community Conference
May 6, 2 PM - May 9, 12 AM
Skill up for the era of AI at the ultimate community-led Microsoft 365 event, May 6-8 in Las Vegas.
Learn moreThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
APPLIES TO: 2013
2016
2019
Subscription Edition
SharePoint in Microsoft 365
Learn how to use a Microsoft PowerShell script to create an audience.
See Add-SPShellAdmin.
You must read about_Execution_Policies.
## Settings you may want to change for Audience Name and Description ##
$mySiteHostUrl = https://www.my.contoso.com
$audienceName = "<Input name of audience>"
$audienceDescription = "<Input description for audience>"
$audienceRules = @()
$audienceRules += New-Object Microsoft.Office.Server.Audience.AudienceRuleComponent("AccountName", "Contains", "jdoe")
#Create an OR group operator between the two audience rules.
$audienceRules += New-Object Microsoft.Office.Server.Audience.AudienceRuleComponent("", "OR", "")
$audienceRules += New-Object Microsoft.Office.Server.Audience.AudienceRuleComponent("AccountName", "Contains", "jlew")
#Get the My Site Host's SPSite object
$site = Get-SPSite $mySiteHostUrl
$ctx = [Microsoft.Office.Server.ServerContext]::GetContext($site)
$audMan = New-Object Microsoft.Office.Server.Audience.AudienceManager($ctx)
#Create a new audience object for the given Audience Manager
$aud = $audMan.Audiences.Create($audienceName, $audienceDescription)
$aud.AudienceRules = New-Object System.Collections.ArrayList
$audienceRules | ForEach-Object { $aud.AudienceRules.Add($_) }
#Save the new Audience
$aud.Commit()
#Compile the new Audience
$upa = Get-SPServiceApplication | Where-Object {$_.DisplayName -eq "User Profile Service Application"}
$audJob = [Microsoft.Office.Server.Audience.AudienceJob]::RunAudienceJob(($upa.Id.Guid.ToString(), "1", "1", $aud.AudienceName))
Note
You can use a different file name, but you must save the file as an ANSI-encoded text file with the extension .ps1.
Click SharePoint Management Shell.
Change to the directory to which you saved the file.
At the PowerShell command prompt, type the following command:
./Audiences.ps1
For additional information about PowerShell scripts and .ps1 files see Running Windows PowerShell Scripts.
For more information about how to create audiences, see AudienceRuleComponent class.
Events
Microsoft 365 Community Conference
May 6, 2 PM - May 9, 12 AM
Skill up for the era of AI at the ultimate community-led Microsoft 365 event, May 6-8 in Las Vegas.
Learn moreTraining
Module
Manage SharePoint Online by using Windows PowerShell - Training
Manage SharePoint Online by using Windows PowerShell
Certification
Microsoft Office Specialist: PowerPoint (Office 2016) - Certifications
Demonstrate that you have the skills needed to get the most out of PowerPoint 2016 by earning a Microsoft Office Specialist (MOS) certification.