Setting Value of UserProfile Property on all users

If you want to change a setting for all user profiles of a user profile service application, e.g. Newsgator Digest Email (“NGReceiveDigestEmail”) this is what you can do:

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
Add-PSSnapin "Microsoft.SharePoint.PowerShell"

# Create Service Context
$site = Get-SPSite http(s)://mysite-host.extension
$serviceContext = Get-SPServiceContext $site

# Get ProfileManager, User Profiles and User Properties
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext)

$userProfiles = $profileManager.GetEnumerator()

$val = "false"

foreach($userProfile in $userProfiles)
# Set New Value
$userProfile["BoolValueNameOfProperty"].Value = $val

#Dispose of site object

The script first gets the SharePoint snap-in silently.

Then itgets the User Profile Manager, which needs to the mysite-host location as a context (don’t forget to dispose the site object in the end, and in production watch out for exceptions that may lead to not executing that line of code).

The enumerator of the profile manager allows iteration of all user profiles. Set the value for the boolean property (for strings or other value types the assignment will look different).

Commit the change and dispose after iteration is finished.


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: