Friday, June 11, 2010

Powershell: Waiting for input from the keyboard

This code waits for a keyboard press. It passes back the character that is pressed, and you can then enact scripts based on the key pressed.

Script follows below:


Write-Host "Press the c key to continue to create a contact with the above variables"
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")


#Exit if the "c" character is not pressed.
if ($x.Character -ne "c")
{
write-Host $x.Character
exit
}

#Continue with rest of code

No comments:

Post a Comment