Change User Regional Setting to “Always follow Web” using PowerShell

  • Posted by: Softree Technology

powershell

I have written this PowerShell script which is related to user regional setting. This below-mentioned code block will help us to change user regional setting to “always follow web” regional setting.

[code lang=”c”]

Write-Host -ForegroundColor cyan ‘Please provide the site url’
$SiteURL = Read-Host “Site Url”

try
{
Add-PSSnapin “Microsoft.SharePoint.PowerShell”
$SPsiteURL = Get-SPSite $SiteURL
$SPserviceContext = Get-SPServiceContext $SPsiteURL
$SPweb = $SPsiteURL.openweb()
$SPusers = $SPweb.SiteUsers

Foreach($SPUser in $SPusers)
{
try
{
$UserLoginName = $SPuser.LoginName
$UserDisplayName = $SPuser.DisplayName

$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($SPserviceContext)

if ($profileManager.UserExists($UserLoginName))
{
$userProfile = $profileManager.GetUserProfile($UserLoginName)
$regSettng = $userProfile[‘SPS-RegionalSettings-FollowWeb’]
$regSettng.Value = $true
$userProfile.Commit()
}
else
{
write-host “User Profile for user” $UserDisplayName “cannot be found.”
}
}
catch
{
$ErrorMessage = $_.Exception.Message
write-host $ErrorMessage
}
}
}
Catch
{
$ErrorMessage = $_.Exception.Message
write-host $ErrorMessage
}

[/code]

This solution is brought to you by our SharePoint professionals.

Softree Consulting employs SharePoint consultants; we are a technology services provider with the aim to help companies achieve exceptional performance through SharePoint. Our dedicated team of SharePoint consultants has the right bent of mind to understand and execute customer requirements.

Be it SPFx or SharePoint add-in developments, SharePoint 2019 developments, web part developments, migrating from SharePoint 2010/2013 to SharePoint 2013/2016/Office 365, Office 365, SharePoint hosted apps development or something else in SharePoint, we strive to deliver the best

Author: Softree Technology

Leave a Reply