Thursday, March 31, 2011

SharePoint 2010: Changing Regional Settings and Locale Settings in Powershell


I just had a client scenario where I have the SharePoint implementation has up to 40 different site collections to maintain. Well, I'm London based and so is my client... what about the default regional settings? Eng-US right? Is my client happy with it? Not really: en-GB, please!.
All right, first of all, let's change the Regional Settings at the level of the Web Application. That's the easy one, as it can be leveraged from SP "Central Admin" site. So simply follow the steps below:
  • Go to "Central Admin"
  • Click "Application management" from the quick launch.
  • Click "manage web applications" under "Web application" heading
  • Select web application on which you want to change the regional settings.
  • From the ribbon click "General setting" and select "General Settings" from the dropdown.
  • Setting modal dialog will appear, you can change the "default time zone" and other settings if you want to change, and click OK.
  • IISReset
And you are done! Wait! What about the locale settings? Aha, the mighty Powershell is happy [once more] to come to the rescue! The following script will do the dirty job for you. In a nutshell it iterates through each site collection within a given web application updating its locale settings and verifying right after if that has been changed successfully.


[Reflection.Assembly]::LoadWithPartialName("System.Globalization") | out-null
clear-host
$SiteCols = Get-SPWebApplication "<SiteCol URL>" | Get-SPSite -Limit ALL | Select URL
foreach ($siteCol in $SiteCols)
{
write-host "---- Site Collection: " + $siteCol.url + "----"

 

get-spweb -site $siteCol.url -limit all |% {
$_.Locale = [System.Globalization.CultureInfo]::GetCultureInfo("en-GB");
$_.Update()
}
#check if culture has been updated
get-spweb -site $siteCol.url -limit all |% {
$_.Locale
}
}


By the way, make sure you are running the script under a site collection administrator; otherwise you'll get a nasty Access Denied exception.


Get-SPWeb : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
At line:4 char:12
+ get-spweb <<<< -site "<SiteCol URL>" -limit all |% {
+ CategoryInfo : InvalidData: (Microsoft.Share....SPCmdletGetWeb:SPCmdletGetWeb) [Get-SPWeb], UnauthorizedAccessException
+ FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletGetWeb


Make Powershell your buddy when it comes to pre-deploy | post-deploy tasks. It will save a lot time that's for granted, but also it will save you heaps of headaches when deploying SharePoint application between different environments.

2 comments:

Vinod Kumar said...

Thanks for the cool post...

Unknown said...

I've just used the powershell script to change Locale and it made my life easier. Thank you.