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:

3 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