0

I have an odd scenario. When I change the Language Preferences of a User using the Edit Profile Properties Page in the User Profile Service Application (SPS-MUILanguages ans SPS-ContentLanguages) the changes are not updated in the Users MySite. The settings are, however, correctly updated in the User Profile Service Application.

Now, the weird thing is, if the user goes to it's my site and just clicks save on it's user profile, then the languages appear. After that updates through the Service Application also work.

Anyway, I need to set the languages for a lot of users using powershell, and I am unable to let every user click save on their mysite. Any ideas? :)

1

We can using the PowerShell below to update the SPS-MUILanguages and SPS-ContentLanguages properties of user profile.

[void][reflection.assembly]::Loadwithpartialname("Microsoft.Office.Server")           
$site=new-object Microsoft.SharePoint.SPSite("http://sp2013/sites/team")         
$serviceContext = Get-SPServiceContext $site
$site.Dispose()           
$upm = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext)
$userProfile = $upm.GetUserProfile("lz\test1")
$userProfile["SPS-MUILanguages"].Value = "en-GB,en-US"
$userProfile["SPS-ContentLanguages"].Value="en-US"      
$userProfile.Commit()

enter image description here

  • As I said, I tried this before and this is indeed working as intended. However, the changes made in the User Profile Service Application using PowerShell will not be reflected in the users MySite. So the changes really don't have an effect until the user explicitly clicks on 'Save my Profile' on his MySite. – Ben Lime Oct 22 '18 at 6:20
0

Well, I finally figured it out. There is another class which is called SPUserSettingsProviderManager. It has methods to set the User's display and content languages.

string language = "en-GB,de-DE";
SPWeb web = SPContext.Current.Web;
SPUser user = web.CurrentUser;

var usp = SPUserSettingsProviderManager.Local.UserSettingsProviders.FirstOrDefault();
var uspCtx = userSettingsProvider.GetProviderContext(user);

usp.UpdateUserLanguageSettings(uspCtx, web.CurrentUser, language, language);
usp.UpdateUserDisplayLanguageSettings(uspCtx, user, language);
usp.UpdateUserContentLanguageSettings(uspCtx, user, language);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.