PowerShell Script

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