SharePoint Tech Blog


Create SharePoint Audiences using Powershell

Filed under: SharePoint — Tags: , — kctnpblog @ 12:49 am

This is a modified version of the codeplex script for creating SharePoint audiences. I find this a bit easier to use since it uses an xml file as its input.
This code requires the SharePoint Powershell Profile to be loaded.

$spsite=Get-SPSite -url $url;
$audmanager=New-Object Microsoft.Office.Server.Audience.AudienceManager($spcontext);
[xml]$adata=Get-Content .\audiences.xml
$adata.Audiences | ForEach-Object {
$newaud.AudienceRules=New-Object System.Collections.ArrayList;
$_.Audience.Rule | ForEach-Object {
$newrule=New-Object Microsoft.Office.Server.Audience.AudienceRuleComponent($property,$operator,$value);
#compile audience
$args=$searchcontext.Name, "1", "1", $audname;

The audiences.xml file:



  1. […] example is based on the Create SharePoint Audiences using Powershell article. Below is the modified script (CreateAudiences.ps1) that does not require a PowerShell […]

    Pingback by Create SharePoint 2010 Audiences Using PowerShell — 01/10/2010 @ 3:59 am

  2. I posted an update that fixes some issues and include a deletion script that can be used as part of the uninstall process. Here is the link:

    Comment by Kirill K. — 01/10/2010 @ 8:53 pm

  3. HI,
    i used this script to create audieances. but its not compiling.
    if i create audience thru CA its automatically compiles.
    requirement-> i need to create a audieance but dont want to add any rules. manually when i create a audience. i cancel the next step wich comes while doing it thru CA. this is for anonymous users no need to add can achive this

    Comment by guru — 18/02/2011 @ 12:06 pm

    • I’m not sure why an audience without rules is required. By defalult all users aren’t part of an audience and therefore should see everything that is not audience targetted. Could you please clarify what is your functional requirement and what are you trying to achieve?

      Comment by kctnpblog — 17/03/2011 @ 10:46 pm

  4. Hello,
    I have a problem while adding rules to audiences.
    I have xml file with all the rules, but not able to add rules to custom user profile properties using the above script.
    But rules are adding to properties other than custom user profile properties.
    Could please help me?

    Comment by Rajashekar — 28/06/2011 @ 1:02 pm

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog at

%d bloggers like this: