So I was asked to collect the preferences of “Activities I am following” (image below) for all the users of our SP2010 My Site.
The resources on web for this being surprisingly limited , I was left with no other option but to turn to my cup of coffee for solution . The coffees helped, the following script lists out the status of options available under “Activities I am following ” of My Site Edit Profile page in SharePoint 2010 , for each user.
$mySiteURL = "https://xxxx" $site = Get-SPSite $mySiteURL $context = Get-SPServiceContext $site; $upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context); $val = "Username,ActivityName,Value" Add-content -path "d:activity_preference.txt" -value $val foreach ($profileupm in $upm.GetEnumerator()) { $myprofile = $profileupm; $usrprofile = $profileupm; $am = New-Object Microsoft.Office.Server.ActivityFeed.ActivityManager($myprofile, $context) $type = $am.GetType() $methodInfo = $type.GetMethod("CopyBasicUserInfo", [reflection.bindingflags]"nonpublic,instance", $null, $usrprofile.GetType(), $null) $methodInfo.Invoke($am, $usrprofile) $preftype = $am.ActivityPreferences.GetActivityPreferencesPerType(); foreach($pr in $preftype) { foreach($a in $am.ActivityTypes) { if ($pr.ActivityType -eq $a) { $val = $usrprofile["AccountName"].ToString() + "," + $a.ActivityTypeName.ToString() + "," + $pr.IsSet.ToString() Add-content -path "d:activity_preference.txt" -value $val } } } }
Comments