Wednesday, July 20, 2011

Change the PowerShell UI Culture

At one of my projects I’m using the new and greater multi language options in SharePoint 2010 and with ASP.Net resources it is really easy to create site in different languages. When I create a site e.g. in Danish the content type display name is translated into Danish, as expected, but when I start my SharePoint managed shell it is running in English context and if I have some PowerShell code which is dependent on language resources, then it will ask in English, but when my site is created in Danish, it may give some weird errors. The solution to this is to set PowerShell CurrentUICulture to be as the site you work with like this.

  1. #Ensure the PowerShell process is running the same culture as SPWeb is created with
  2. $web = Get-SPWeb "http://win-l2sfc3oetnn"
  3. [int]$lcid = $web.Language
  4. $culture = new-object "System.Globalization.CultureInfo" $lcid
  5. [System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture