SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
#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`
share|improve this question
Anil, could you please format your code and move the comment you left for Per Jackobson up into the comments section of his answer? – Robert Kaucher Apr 13 '12 at 12:50
Question originated from here: – Kit Menke Apr 13 '12 at 13:28
@RobertKaucher Hi Robert i had formatted the code and added the logic to repeat it for all users but now i am getting the following error.Can you please help 'You cannot call a method on a null-valued expression' – Anil Apr 13 '12 at 14:39
up vote 0 down vote accepted

Replace the foreach on userprofiles with this while($profile1.MoveNext()) and $profile1.Current will return you the current user profile. Sample

$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$iterator = $upm.GetEnumerator()
   Write-Host $iterator.Current.DisplayName
share|improve this answer
Can you please see my updated code with the logic you told me . i am getting the following error .You cannnot call a method on null valued expression – Anil Apr 13 '12 at 15:04
The line $methodInfo = $type.GetMethod(..), Replace $profile1.GetType() with $profile1.Current.GetType(). – sssreddy Apr 13 '12 at 15:21
The object is null. I imagine that sssreddy's suggestion will fix that. – Robert Kaucher Apr 13 '12 at 15:28
Thank you very much both of you .It fixed the issue ...You really saved me a lot of time .... – Anil Apr 13 '12 at 15:38
Hi All , If i want the Update happen only to group of audience that i had created instead of the complete user profile ,Can you tell me how i can achieve that using power shell – Anil Apr 17 '12 at 17:14

You are piping ActivifyTypes into an foreach which you're also using to loop through $AllProfiles you need two foreach instead of one

share|improve this answer
Thanks for the answer but when i am running it through the userprofile enumerator it is giving me the following error. Can you please help me. But it is running in the loop > You cannot call a method on a null-valued expression. At > C:\Users\servicet\Desktop\ActivityFeedComplete.ps1:31 char:19 > + $methodInfo.Invoke <<<< ($am, $profile1.NTName) > + CategoryInfo : InvalidOperation: (Invoke:String) [], RuntimeException > + FullyQualifiedErrorId : InvokeMethodOnNull – Anil Apr 13 '12 at 14:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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