August 26, 2013

SharePoint 2013: Modify "Activities I want to share in my newsfeed" for all users using PowerShell

Task

I needed to modify "Activities I want to share in my newsfeed" value centrally for all users in a SharePoint 2013 farm.

Solution

With the following PowerShell, you can set all options checked.

$Site = Get-SPSite -Limit 1    

$ServiceContext = Get-SPServiceContext($Site)
$ProfileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)
$Profiles = $ProfileManager.GetEnumerator()

foreach ($Profile in $Profiles)
{
# 4095 is decimal value of 111111111111, meaning all options are checked.
# Binary value describes what options are checked
# so 000000000001 --> 1 (1 being the value you want to set as the field value
# would mean only "Participation in communities" would be checked
$Profile["SPS-PrivacyActivity"].Value = 4095
$Profile.Commit()
}



 


Technorati Tags:

10 comments:

  1. Hi,

    thank you for that post...
    I tried to use the script but got the following error. Can you help?

    New-Object : Ausnahme beim Aufrufen von ".ctor" mit 1 Argument(en):
    "UserProfileApplicationNotAvailableException_Logging ::
    UserProfileApplicationProxy.ApplicationProperties ProfilePropertyCache does
    not have 67432d2a-6d29-4cb4-a7a0-e617b565d5f3"
    In C:\temp\NeewsfeedSettings.ps1:4 Zeichen:19
    + $ProfileManager = New-Object
    Microsoft.Office.Server.UserProfiles.UserProfileMan ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ~~~
    + CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvoca
    tionException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.Power

    ReplyDelete
  2. Hi Dominic,
    Make sure the account you run the PowerShell script with has Full Control permission on the User Profile Service Application. Alternatively log in and run the script with account that has such permissions.

    ReplyDelete
  3. Hi again,
    I ran the Shell as farm admin and it works. great!
    Thanks.....

    ReplyDelete
  4. Hi, how can i target users in a specific AD group with this script?
    Cheers
    Shane

    ReplyDelete
    Replies
    1. SharePoint User Profile Service doesn't know anything about AD groups so you need to fetch AD group user account names first, then do a for each loop to modify each user profile one by one.

      Delete
  5. Great post. Works for me.
    The binary number sequence is other way around. e.g. If you want to mark only Participation in communities, you will have to provide value 2048 (100000000000). Tested in SP2013.

    ReplyDelete
    Replies
    1. Thank you Xeeshan for the update. Much appreciated!

      Delete
  6. Do you know of a way I can do this in SharePoint Online?

    ReplyDelete
  7. Have you tried this which lists properties including this, and modify it to update the value? https://gallery.technet.microsoft.com/office/Retrieve-all-SharePoint-357e2936#content

    ReplyDelete
  8. omg thank you so much! there is absolutely no documentation about this, and every blog about the old outdated 2010 Feed wich is done entirely different.
    this helps me really a lot, even years later, hahah.

    ReplyDelete