#Add SharePoint PowerShell SnapIn if not already added
 if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"

[void] [System.Reflection.Assembly]::LoadWithPartialName("System")

$site = Get-SPSite "http://mysite/"
$context = Get-SPServiceContext $site;
$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context);
$profile1 = $upm.GetEnumerator()


        $am = New-Object Microsoft.Office.Server.ActivityFeed.ActivityManager($myprofile1, $context)

        $type = $am.GetType()
        $methodInfo = $type.GetMethod("CopyBasicUserInfo", [reflection.bindingflags]"nonpublic,instance", $null, $profile1.GetType(), $null)

        $apptList = New-Object System.Collections.Generic.List[Microsoft.Office.Server.ActivityFeed.ActivityPreferencePerType]

        $am.ActivityApplications["UserProfileChange_Gatherer"].ActivityTypes | ForEach-Object {
              $appt = New-Object Microsoft.Office.Server.ActivityFeed.ActivityPreferencePerType
              $appt.ActivityType = $_ 
              $Username = $profile1.Current.DisplayName

              if($_.ActivityTypeName -eq "Birthday_Reminder") {
                $appt.IsSet = $false
                write-host "Updating Activity Feed Property Birthday_Reminder for " $Username              

               $appt.IsSet = $true
            } # For Each Object Ending
} # While Userprofile Ending`enter code here`

While the above code is working for all user profiles i want to limit the update only to a specific group of users ,For that purpose i had created audience in admin ,But i don't know how to call that group of Audience from Power Shell Code.Can anyone please suggest me how to achieve that..


To work with audiences you need to get the AudienceManager

To get the userprofiles for an audience you can do the following:

$site = Get-SPSite "http://mysite/" 
$context = Get-SPServiceContext $site; 
$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context); 
$audmgr = New-Object Microsoft.Office.Server.Audience.AudienceManager($context)
$aud = $audmgr.GetAudience("Managers")
$aud.GetMembership() | % {$upm.GetUserProfile($_.NtName)}
  • Can you give me some more insight on that . I am very new to powershell...
    – Anil
    Apr 17 '12 at 20:07
  • Hi I am using the audience manager class but how can i loop through only specific group of audience ...
    – Anil
    Apr 17 '12 at 20:23
  • Example added to answer Apr 18 '12 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.