#PSTip Provide CapsLock status in Read-Host prompt

In Windows, you get a message about the CapsLock status when logging on to Windows OS and with CapsLock on. You see this kind of experience in many other applications including web applications.

A similar experience, if not the same, can be provided in a simple manner when asking for password input using Read-Host cmdlet in a script.

Read-Host -Prompt "Enter Password $(if([console]::capslock){'(CapsLock is ON)'})"

Here is how it looks:


About the author: Ravikanth C

Ravikanth is the founder and editor of the PowerShell Magazine. He is also a PowerShell MVP who works at Dell Inc. He blogs at http://www.ravichaganti.com/blog and you can follow him on Twitter @ravikanth.

Related Posts