4

#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:

capslock

Filed in: Columns, Tips and Tricks Tags: ,

4 Responses to "#PSTip Provide CapsLock status in Read-Host prompt"

  1. DVS says:

    What else can you do with “[console]::”? What are “-static” variables?

    [console] | Get-Member -Static

  2. pamarths says:

    Very useful tip!!..

Leave a Reply

Submit Comment

© 2016 PowerShell Magazine. All rights reserved. XHTML / CSS Valid.
Proudly designed by Theme Junkie.
%d bloggers like this: