Powershell: Check and Toggle Numlock during logon

This is one that comes up anywhere, especially in VDI/RDS-type environments: Numlock.

In my experience there are no real good ways of controlling this without scripts, too many variables, as the final state of numlock depends on the state on the client computer, the VM and whatever settings are in the user profile.

The powershell script below first checks for the state of the numlock key: If ([console]::NumberLock -eq $False), and when False, proceeds to send the command to toggle it, turning it on.


If ([console]::NumberLock -eq $False) {
$wsh = New-Object -ComObject WScript.Shell