Closing a PowerShell window with other keys [SOLVED]
Posted: 2023-Aug-31, 4:47 pm
I have this script - but it only closes the PS window when I press Enter [thus ignoring addition of being able to use also Space and Esc]:
How can this be fixed?
Code: Select all
Write-Host "To close this window press either:"
Write-Host " Enter"
Write-Host " Space"
Write-Host " Esc"
do {
$key = $Host.UI.RawUI.ReadKey('NoEcho, IncludeKeyDown').Character
} while ($key -notin @(
[char]13, # Enter
' ', # Space
[char]27 # Escape [carriage return]
)
)
Read-Host