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
} }  } }

2 Replies to “SharePoint MySite – PowerShell script to get the “Activities I am following” preferences”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.