Home > Language Pack, Powershell, SharePoint, SharePoint 2010, SharePoint 2013 > Activate selected languages on all subsites using Powershell

Activate selected languages on all subsites using Powershell

December 17, 2012 Leave a comment Go to comments

Hi friends.

If you ever find yourself wanting to enable a particular language or set of languages on a site Collection and all subsites, and if you do NOT want to enable all languages installed but rather Control what gets enabled? Here is a scripot that will help you.
In my own scenario I had 4 site Collections, each tageted for a different nordic country, Sweden, Norway, Finland and Denmark. So, the need is to have enabled English for all and only the countrys language for the 4 site Collections.

Looking for an existing sample code to use, I found many that were copies of the MSDN sample, this is a good piece of code but it enables all languages installed.

So, trying to find a clever way of selecting what language got enabled, I found an old script I created for the same customer, the solution was so simple it works!
While iterating thru all the installed languages, site by site, I check the displayname of the Language and add criteria fro the languages to install. Beautifully simple 🙂
There is Little difference between this and the MSDN sample code, but is was an important difference to me.

This is what I used in the end:

# Enables SELECTED installed languages for each subsite in a site collection
 $spSiteURL = http://sharepoint.balkestahl.se/sites/subsitecountry
 $spSite = Get-SPSite -Identity $spSiteURL
 foreach ($spWeb in $spSite.AllWebs)
 {
   $spWeb.IsMultilingual = $true
   $WebRegionSettings = New-Object Microsoft.SharePoint.SPRegionalSettings($spWeb)
   foreach ($language in $WebRegionSettings.InstalledLanguages)
   {
     If ($language.DisplayName -eq "English" -or $language.DisplayName -eq "Swedish")
     # Add the displayname of any langauge you have installed: -or $language.DisplayName -eq "Norwegian" -or $language.DisplayName -eq "Finnish" -or $language.DisplayName -eq "Danish"
     {
        write-host -BackgroundColor Green -ForegroundColor Black "Update -" $spWeb "site with LCID:" $language.DisplayName
        $culture = New-Object System.Globalization.CultureInfo($language.LCID)
        $spWeb.AddSupportedUICulture($Culture)
     }
     else
     {
        Write-host " Language not activated: " $language.DisplayName " on site " $spWeb.Name
     }
   }
   $spWeb.Update()
 }

This saved me hours and hours…or made it possible 🙂
The running of the script looks something like this, in my case around 3000 times for the Swedish collection, all in all, 50.000 subsites!):

Script

Before running the script, in each site, you have these settings:
(Accessed under: Site Settings/Language Settings, path: /_layouts/muisetng.aspx)
Languages1x

And what we want to do, is check the box for the selected language(s) and move on to the next.

Languages2x

When adding the criteria to the If statement, use the displaynames exactly like in the list in Site Settings/Language Settings:

LanguagesDisplayNamesx

This script saved me, I hope it can do the same for some of you.


_________________________________________________________

Enjoy!

Regards

Twitter | Technet Profile | LinkedIn

Advertisements
  1. August 28, 2013 at 13:40

    Excellent, this script really did do wonders…. Muchas Gracias!

  1. No trackbacks yet.

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 )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: