How to change regional settings with PowerShell

Recently I needed to change the regional settings for all the sites and site collection in a SharePoint 2013 farm, so I did it with Powershell.

But also, at the same time I needed to do it for a SPO tenant, so let’s PowerShell!

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
foreach ($webApplication in Get-SPWebApplication) {
Write-Host
Write-Host "Processing $webApplication"
Write-Host "******************************"

foreach ($site in $webApplication.Sites) {
$webs = $site.AllWebs
Write-Host
Write-Host "Processing $site"
Write-Host "******************************"
foreach ($web in $webs) {
$culture=[System.Globalization.CultureInfo]::CreateSpecificCulture("es-es")
$web.Locale=$culture
$web.Update()
$web.Dispose()
Write-Host $web.Url
}
}
}

#If you need to change the timezone and local id in SharePoint Online, you can do it using the following:

#This is to change the LocalID
#First, set up your ClientContext in the normal manner:
$Password = ConvertTo-SecureString -String "yourPassword" -AsPlainText -Force;
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext("https://tenant.sharepoint.com/sites/yourSiteCollection");
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials("admin@company.onmicrosoft.com", $Password);
#Now we need to set up our target web site object:
$web = $ctx.Web;
$ctx.Load($web);
$ctx.ExecuteQuery();
#Next, update the settings. In this example, I’m setting the LocaleId to 2057 (en-UK)
$web.RegionalSettings.LocaleId = 2057;
$web.Update();
#Finally, run the ExecuteQuery method to apply the changes:
$ctx.ExecuteQuery();

#The following is to change the zoneID for personal sites
if($user.LoginName.Contains('@'))
{
$persweb=$user.LoginName.Replace(".","_").Replace("@","_")
$persweb=$myhost+"/personal/"+$persweb
Write-Host $persweb
Set-SPOUser -Site $persweb -LoginName $username -IsSiteCollectionAdmin $true
$AdminUrl=$persweb

Set-SPoUserRegionalSetings -Username $Username -AdminPassword $AdminPassword -Url $AdminUrl -TimeZoneID $TimeZoneID
}

If you need to know which time zone ID is your region, visit: https://gist.github.com/mj1856/9542228 to check it

And If you need to check your local ID, visit: https://msdn.microsoft.com/en-gb/goglobal/bb964664

Ref: https://blogs.technet.microsoft.com/fromthefield/2015/04/13/office-365-change-the-locale-of-all-onedrive-for-business-sites-using-powershell/
https://gallery.technet.microsoft.com/Update-the-time-zones-in-67a5644a

Advertisements

2 thoughts on “How to change regional settings with PowerShell

  1. This script only updates the site collections for on-prem SharePoint and OneDrive, but not all Site Collections in SharePoint Online

    Like

    1. Hey Alex, the second part of the script is where the references to SPO take effect, take into account that the commands starts by Set-SPO, it was a while since the last time I executed these commands, so could be a chance that it have been changed.

      Like

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

w

Connecting to %s