#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`
  • Anil, could you please format your code and move the comment you left for Per Jackobson up into the comments section of his answer? Apr 13, 2012 at 12:50
  • Question originated from here: sharepoint.stackexchange.com/q/31958/2070
    – Kit Menke
    Apr 13, 2012 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, 2012 at 14:39

2 Answers 2


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
  • 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, 2012 at 15:04
  • The line $methodInfo = $type.GetMethod(..), Replace $profile1.GetType() with $profile1.Current.GetType().
    – sssreddy
    Apr 13, 2012 at 15:21
  • The object is null. I imagine that sssreddy's suggestion will fix that. Apr 13, 2012 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, 2012 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, 2012 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

  • 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, 2012 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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