Emulate a keyboard button via the Command Line

How do I toggle numlock status using PowerShell.

Use the following script:

$wsh = New-Object -ComObject WScript.Shell
$wsh.SendKeys('{NUMLOCK}')

Source StackOverflow answer PowerShell: Toggle “Num Lock” on and off. by Andy Arismendi

As pointed out by ABashore in his comment this can be shortened as follows:

$wshell.SendKeys('{NUMLOCK}')

Here's a powershell line that will toggle your NUMLOCK. I've tested this and it works on my Logitech K120 USB keyboard.

$wshell.SendKeys('{NUMLOCK}')

Here's a list of the other SendKey codes.

If you need to send the keystroke to an interactive application, more code will be needed.