Download SharePoint Language Packs with PowerShell v3

If your SharePoint environment needs to cater for a global audience, chances are you’ll need to install a bunch of Language Packs. This can be tedious and time consuming, and frankly, I’m quite lazy. I’d much rather let a computer do the work…

After a quick Google, I found a couple of solutions that looked pretty good:

http://splanguagepacks.codeplex.com/

http://sharepointryan.com/2011/06/09/download-all-sharepoint-2010-language-packs-using-powershell-update/

The first option seems as if it would work perfectly, but I’d rather not have another application sat clogging up my desktop. The second would also technically meet my requirements, however it’s a little too hardcoded, and would need me to update all the paths if / when a patch came out. To get the best of both worlds, I decided to create my own version of the script.

How it works

To get rid of the hardcoded URL’s, I’m using PowerShell v3’s Invoke-WebRequest. This allows me to scrape the HTML for the page, and find all of the available languages.

Download SharePoint Language Pack

From here, it opens the language specific download page, and finds the “download” link. Specifically, the script gets the first link which ends in “.exe” or “.img”. It then uses Start-BitsTransfer, which kicks off the download of the file. It does this for each language. Once this is done, the script waits for all downloads to finish before finalizing them.

The Code

The PowerShell creates a new function called Get-SPLanguagePacks. It takes 2 parameters: The path, which is the location for all downloads to be saved to. The second parameter is the DownloadId. This is key to making the code reusable and less hardcoded. You can find this by going to the download page. It is the “id” parameter in the URL

Language Pack ID in Query String

Once you have this information, you can run the command like so:

1
2
3
4
5
6
7
8
#Download the SharePoint Server 2010 Service Pack 2 Language Packs
Get-SPLanguagePacks -Path "c:\LanguagePacks\2010SP2" -DownloadId 3411

#Download the SharePoint Server 2013 Language Packs
Get-SPLanguagePacks -Path "c:\LanguagePacks\2013RTM" -DownloadId 37140

#Download the SharePoint Server 2013 SP1 Language Packs
Get-SPLanguagePacks -Path "c:\LanguagePacks\2013SP1" -DownloadId 42004

To run the commands, just ensure you have the powershell loaded up in your current session:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Function Get-SPLanguagePacks{
param($Path,$DownloadId)
if(!(Test-Path $Path)){
New-Item $Path -ItemType "Directory"
}
cd $Path
$request = Invoke-WebRequest http://www.microsoft.com/en-gb/download/details.aspx?id=$DownloadId
[xml]$options = $request.AllElements | where-object {$_.name -eq "newlocale"} | select-object -ExpandProperty OuterHtml
$options.select.option | Foreach-object {
$path = $filePath
$text = $_.innerText
$code = $_.value
write-host "Downloading language pack $text "
$fileRequest = Invoke-WebRequest "http://www.microsoft.com/$value/download/confirmation.aspx?id=$DownloadId"
$fileLink = $fileRequest.Links | where-object {$_.href -like "*.exe" -or $_.href -like "*.img"} | Select-Object -First 1 -ExpandProperty href
New-Item -ItemType "Directory" -Name $text | out-null
Start-BitsTransfer $fileLink -Destination .\$($text) -Asynchronous -DisplayName "$text Transfer" | Out-Null
}

$transfers = Get-BitsTransfer
write-host "Downloading..." -NoNewline

while(($transfers | where-object {$_.JobState -eq "Connecting" -or $_.JobState -eq "Transferring"}).Count -gt 0){
write-host "." -NoNewline
sleep 5
}
$transfers | Where-Object {$_.JobState -eq "Transferred"} | Complete-BitsTransfer
}

Limitations

While none of the download links are hard coded, it does rely on a certain HTML structure on the Microsoft download centre. If the site gets a revamp, then the code is likely to stop working. This is a risk I’m willing to take, as it isn’t likely to update often, and should be a relatively minor change to the PowerShell if it does.

The code above will actually download ALL available language packs. Chances are, you’ll never need all of them. I figured because it’s happening automatically, I don’t mind having it download them all. It’s nice to have them ready in case I do need to install them. If you don’t want to bother downloading them all, you can easily add a Where-Object in before the Foreach-Object, and select the languages you do want to install, either by name, or country code.

Also, note really a limitation, but a note… this script is automatically downloading executable files from the internet. I feel that the Microsoft site is probably a trustworthy source, however you should probably understand the risks before running this in a production environment.

What next?

Once they’re downloaded, you’ll need to install the Language Packs. That’s beyond the scope of this blog, however carrying on the PowerShell should be easy. There are plenty of blog posts covering the next steps…

http://blog.sharepoint-voodoo.net/?p=97

http://blogs.msdn.com/b/chadray/archive/2013/10/15/script-for-installing-sharepoint-2013-language-packs.aspx