Change Newsfeed setting of all User profiles in SharePoint 2010 – Part 1

In SharePoint 2010, Newsfeed provides fancy functionality, which allows user to keep well socializing inside of organization:

My Newsfeed is the default page when a user accesses his or her My Site. This section displays the What’s New page, which provides a feed of recent activities related to a user’s specified colleagues and interests. Users can customize their newsfeeds by adding or removing colleagues they are interested in, specifying interests, and configuring the kind of activities they want to follow, such as when a colleague tags information with a shared interest. (MSDN http://technet.microsoft.com/en-us/library/ff382643.aspx)

Compare to Interests and Email Notification, “Activities I am following” does not have a mapping property in the Central Admin. I just encountered a client requirement last week, who wants to initialize the activity events for all the users; in other words, some of items in the section will be unchecked.

The above section of activities is extensible through object model and hence you can expect more items to appear under this list of activities one can follow. The modification to each user activities is stored under ActivityPreference in the profile database.

Below is PowerShell script to change Newsfeed setting.

NOTE: I have not found a solution to initialize the checkbox automatically when a new user profile is created. 

*** I have a solution for new user in my second post Change Newsfeed setting of all User profiles in SharePoint 2010 – Part 2

##########################   XML file : ConfigActivityFeed.xml ############################

<?xml version="1.0" encoding="utf-8" ?>
<ActivityTypes>
     <URL>http://dev.mysite.com/</URL>
     <ActivityType Name="StatusMessage" IsSet="True"></ActivityType>
     <ActivityType Name="SocialTaggingByAnyone" IsSet="False"></ActivityType>
     <ActivityType Name="SocialRatings" IsSet="True"></ActivityType>
     <ActivityType Name="DLMembershipChange" IsSet="True"></ActivityType>
     <ActivityType Name="SharingInterest" IsSet="True"></ActivityType>
     <ActivityType Name="SocialTaggingByColleague" IsSet="True"></ActivityType>
     <ActivityType Name="NoteboardPosts" IsSet="True"></ActivityType>
     <ActivityType Name="TitleChange" IsSet="True"></ActivityType>
     <ActivityType Name="ManagerChange" IsSet="False"></ActivityType>
     <ActivityType Name="BlogUpdate" IsSet="True"></ActivityType>
     <ActivityType Name="WorkplaceAnniversary_Reminder" IsSet="False"></ActivityType>
     <ActivityType Name="WorkplaceAnniversary_Today" IsSet="False"></ActivityType>
     <ActivityType Name="ColleagueAddition" IsSet="True"></ActivityType>
     <ActivityType Name="ProfilePropertyChange" IsSet="True"></ActivityType>
     <ActivityType Name="Birthday_Reminder" IsSet="False"></ActivityType>
     <ActivityType Name="Birthday_Today" IsSet="False"></ActivityType>
</ActivityTypes>

#######################   ConfigActivityFeed.ps1 ###############################

#----------------Get the xml file---------------------------------------------------------------

[xml]$xmlData=Get-Content "ConfigActivityFeed.xml"

#----------------Set Activity Feed Preferences--------------------------------------------------
function SetActivityFeed
{
Param(
[Microsoft.Office.Server.ActivityFeed.ActivityManager]$UserActivityManager,
[string]$User
)

#---------------------------------------------------------------------------------------------------------
try
{
   $apptList = New-Object System.Collections.Generic.List[Microsoft.Office.Server.ActivityFeed.ActivityPreferencePerType]
   $appts = $UserActivityManager.ActivityPreferences.GetActivityPreferencesPerType()

   $ats = $UserActivityManager.ActivityTypes

   $User >> ".\ActivityTypeName.txt"

   foreach($appt in $appts)
   {
      $appt.ActivityType.ActivityTypeName >> ".\ActivityTypeName.txt"
 #----------------------------------------------------------------------------------
 # IsSet -> indicating whether a user wants to see the ActivityType object stored
 # in this ActivityPreferencePerType in a feed
 #----------------------------------------------------------------------------------
      $appt.IsSet >> ".\ActivityTypeName.txt"
 #----------------------------------------------
 # Change the value of IsSet to check/uncheck
 #----------------------------------------------
      $xmlData.ActivityTypes.ActivityType | ForEach-Object{
         $typeName = $_.Name
         if($appt.ActivityType.ActivityTypeName.Equals($typeName))
         {
            $appt.IsSet = [System.Convert]::ToBoolean($_.IsSet)
         #write-host -f red "Check ActivityType: " $appt.ActivityType.ActivityTypeName}
         } 
      }
      $apptList.Add($appt)

   } 
### Display value of properties
<#
 foreach($type in $ats)
 {
 write-host -f green "ActivityTypeNameLocStringName:" $type.ActivityTypeNameLocStringName
 write-host -f blue "ActivityTypeNameLocStringResourceFile:" $type.ActivityTypeNameLocStringResourceFile
 write-host "ApplicationId:" $type.ApplicationId
 }
 #>
}
catch
{
   Get-Date >> ".\ActivityFeedErrLog.txt"
   $_.Exception.ToString() >> ".\ActivityFeedErrLog.txt"
}

$line = "--------------------------------------"
$line >> ".\ActivityTypeName.txt"
### Sets the current user's preferences for each ActivityType object managed by the ActivityManager
$UserActivityManager.ActivityPreferences.SetActivityPreferencesPerType($apptList)
$UserActivityManager.ActivityPreferences.Commit()
$UserActivityManager.ActivityPreferences.Refresh()

}

#----------------Get Activity Manager with specific user account------------------------------------------
function ConfigActivityFeed()
{
   $snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
   if ($snapin -eq $null)
   {
      Write-Host "`nLoading SharePoint Powershell Snapin`n"
      Add-PSSnapin "Microsoft.SharePoint.Powershell"
   }

Try
{
   $site = Get-SPSite $xmlData.ActivityTypes.URL
   $context = Get-SPServiceContext($site)
 ### Get User Profile
   $upm = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)

   [void][System.Reflection.Assembly]::LoadWithPartialName("System")
   $user = $upm.GetUserProfile("ad\lixuan0125")
 ### Iterate all the user profiles
 <#[System.Collections.IEnumerator] $en = $upm.GetEnumerator()
 while($en.MoveNext())
 {
 $user = [Microsoft.Office.Server.UserProfiles.UserProfile]($en.Current)
 $str = [Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName
 $userName = $user[$str].Value.ToString()
 write-host -f blue $userName
 #>
 ### Get Activity Feed Manager
    $am = New-Object Microsoft.Office.Server.ActivityFeed.ActivityManager($user, $context)

 ### Using reflection to set preference for user; otherwise, only get preference of account which is used to login server
    $methodInfo = $am.GetType().GetMethod("CopyBasicUserInfo", [reflection.bindingflags]"nonpublic,instance", $null, $user.GetType(), $null)
 ### Invokes the method represented by the current object instance, using the specified parameters
 ### Invoke(Object obj, Object[] parameters)
    $methodInfo.Invoke($am, $user)

    SetActivityFeed -UserActivityManager $am -User $userName
 #}
}
Catch
{
   write-error $_.Exception
   Get-Date >> ".\ActivityFeedErrLog.txt"
   $_.Exception.ToString() >> ".\ActivityFeedErrLog.txt"
}

write-host -f red "Done"
$site.Dispose()

}

#----- Call function ---

ConfigActivityFeed
Start-Sleep -Seconds 50;
Advertisements

31 thoughts on “Change Newsfeed setting of all User profiles in SharePoint 2010 – Part 1

  1. Pingback: Change Newsfeed setting of all User profiles in SharePoint 2010 – Part 2 « lixuan0125

  2. Pingback: SharePoint 2010 uncheck unnecessary Newsfeeds from User Profiles « SukhijaVikas's Blog

  3. You’re so awesome! I don’t suppose I have read anything like this before. So wonderful to find somebody with unique thoughts on this topic. Seriously.. many thanks for starting this up. This web site is something that is needed on the internet, someone with a little originality!

  4. Spot on with this write-up, I absolutely think this amazing site
    needs much more attention. I’ll probably be back again to read more, thanks for the info!

  5. I’ve read a few just right stuff here. Certainly worth bookmarking for revisiting. I wonder how a lot effort you place to make such a wonderful informative site.

  6. Hi there! This post could not be written any better!

    Reading this post reminds me of my old room mate! He always kept
    talking about this. I will forward this article to him.
    Fairly certain he will have a good read. Thanks for sharing!

  7. Hello There. I found your blog using msn. This is a really
    well written article. I’ll make sure to bookmark it and return to read more of your useful info. Thanks for the post. I’ll certainly comeback.

  8. Pingback: Confluence: Microsoft SharePoint

  9. I’ve been surfing online greater than 3 hours these days, but I by no
    means found any attention-grabbing article like yours.

    It is beautiful value enough for me. Personally,
    if all website owners and bloggers made just right content material as you did,
    the internet might be a lot more helpful than ever before.

  10. Do you mind if I quote a couple of your posts as long as I provide
    credit and sources back to your weblog? My blog site is in the very same area of interest as yours and my users would certainly benefit from a lot of the information you
    provide here. Please let me know if this alright with you.

    Regards!

  11. Hii a good post. Just wondered why we can’t set “Activities I want to share in my newsfeed” ShareAll by default. As it is with “Email notifications” . Does this depend on how the user profile is created ( by sharepoint ) or say in my case with PS when
    I have been auto creating profiles for bulk setting certain properties .

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s