Skip to content

Instantly share code, notes, and snippets.

@bazzilic
Last active June 3, 2025 18:23
Show Gist options
  • Save bazzilic/6d077e319ff36cbe9f4182c07f77821f to your computer and use it in GitHub Desktop.
Save bazzilic/6d077e319ff36cbe9f4182c07f77821f to your computer and use it in GitHub Desktop.

How To Use This Script

First, you need to enable script execution in your PowerShell: https://superuser.com/a/106363

Second, make a folder where you will store this script. For example, it could be ~/scripts, where ~ is a system substitute for your home folder (C:\Users\<your login>). Create the folder and download the FixAutoAddedKBLayout.ps1 script in it. Running this script (right-click and run) should fix the keyboard layouts.

This won't fix the layouts forever, the extra layout will come back at some point. So what I did was setup a schedule to run this script every once in a while. This is done using the RegisterCronJob.ps1 script. Put it in the same folder and run it. That should register a schedule to run FixAutoAddedKBLayout.ps1 every time the computer is idle for 3 minutes. You can edit the condition to start the script using information on that page.

param (
[String]$LanguageToFix = 'en-SG'
)
$lng = Get-WinUserLanguageList
$lng.Add($LanguageToFix)
Set-WinUserLanguageList -Force $lng
$lng.Remove( ( $lng | Where-Object LanguageTag -like $LanguageToFix ) ) 2>&1 | Out-Null
Set-WinUserLanguageList -Force $lng
schtasks /create /sc ONIDLE /i 3 /tn 'Fix keyboard layout issue' /tr "$(pwd)\FixAutoAddedKBLayout.ps1"
@rami-alloush
Copy link

How do I run this?! Executing from PowerShell gives the following error

.\FixAutoAddedKBLayout.ps1 : File C:\Users\ramia\OneDrive\Desktop\FixAutoAddedKBLayout.ps1 cannot be loaded because
running scripts is disabled on this system. For more information, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ .\FixAutoAddedKBLayout.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

@rami-alloush
Copy link

The actual solution is here
https://answers.microsoft.com/en-us/windows/forum/all/windows-adding-afrikaans-keyboard/0e2d7101-308a-4a70-a2f3-e4dbf7f064b2?page=3
Remove the not needed language from Office 2016 Language Preferences

@bazzilic
Copy link
Author

bazzilic commented Jan 2, 2020

This solution you mention doesn't reliably work.
As for the error you were getting, you need to enable execution of scripts in your Powershell: https://superuser.com/questions/106360/how-to-enable-execution-of-powershell-scripts

@Rexeh
Copy link

Rexeh commented Nov 13, 2023

Thanks, works great. Very annoying windows bug.

@laymeh
Copy link

laymeh commented Feb 15, 2024

Hi, I tried running the script and my target lang is en-US, but it gives me an "Cannot find an overload for "Remove" and the argument count "1"
I have 2 main languages which is Ukrainian and English UK, so should I change something in the code or something?
Will be really grateful for any help since I am not that good with codes and can't really understand why it's not running the way it should :)
Screenshot 2024-02-12 190102

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment