Powershell script to deploy language during autopilot (based on choosed keyboard)

So Alex Semibratov made a script that, based on the choice of the second (additional) keyboard, changes the language of the system to the one matching the keyboard language choice and sets everything as default. (Full localization of Windows 10/11 from Autopilot)

I came up with the idea that you can use the selection of the first keyboard (skipping the additional keyboard selection) which seems more obvious to the user. I found an entry in the registry where there is information about the keyboard language used:

$rpath = 'registry::HKEY_USERS\.DEFAULT\Keyboard Layout\substitutes'
$KB_lng_code = Get-Item -Path $rpath |select -ExpandProperty property | %{Get-ItemProperty $rpath | select -ExpandProperty $_}

Switch ($KB_lng_code)
 "0000040a" {Write-Host "es-es"}
 "00000411" {Write-Host "ja-jp"}
 "00000804" {Write-Host "zh-CN"}
 "00000404" {Write-Host "zh-TW"}

I edited the first part of Alex script:

 Start-Transcript -Path "$env:PROGRAMDATA\Localization.log" | Out-Null

 $regpath = 'registry::HKEY_USERS\.DEFAULT\Keyboard Layout\substitutes'
$Languages = Get-Item -Path $regpath |select -ExpandProperty property | %{Get-ItemProperty $regpath | select -ExpandProperty $_}
 if ($languages -eq "00000415") {$languages = 'pl-pl'}
elseif($languages -eq "0000040c") {$languages = 'fr-fr'}
elseif($languages -eq "00000816") {$languages = 'pt-pt'}
elseif($languages -eq "0000040a") {$languages = 'es-es'}

$Language = $languages

$inputLanguageID = $null

 if ($language -eq $null)
     $IPInfo = Invoke-RestMethod http://ipinfo.io/json
     $Language = $IPInfo.country

$GeoID = (Get-ItemProperty -Path 'registry::HKEY_USERS\.DEFAULT\Control Panel\International\Geo').Nation

 $LanguageExperiencePacklanguage = $Language

and the part with languages filled with the proper values: example

 {$_ -eq "00000415" -or $_ -eq "pl-pl"} {  
		$applicationId = "9nc5hw94r0ld"	
		$GeoID = 191        
        $LanguageExperiencePacklanguage = "pl-PL"
       if($inputLanguageID -eq $null) {$inputLanguageID = "0415:00000415"}

It finds the current keyboard language and installs the proper system language BUT I think it is kind of messy. Any ideas how to make it better?


Welcome to the forum. :wave:t4:

The blog post you’re refering to is actually really new. Why don’t you contact the author via the comment section? He’s probably most qualified to judge your modification. :wink:

Regardless of that - when you post code you should remove the > characters on all lines as it prevents people willing to help you to easily copy and try your code.

1 Like

Being honest, I did not come up with the idea of writing in the comments to the original script or to the creator himself. Good point, thank you.