What is the value returned by read-host when the cancel button is pressed

I though the value would be $null, but is not. What value is returned when I click cancel in the read-host windows prompt. It gives me an error when i click on cancel.

thanks

November 28th, 2012 3:14am

it looks like $null to me, assuming you are using the ISE:

PS C:\Windows\System32\WindowsPowerShell\v1.0> $a = read-host "please cancel me"

____________________________________________________________________________
PS C:\Windows\System32\WindowsPowerShell\v1.0> if ($A -eq $null) {'null'}
null

____________________________________________________________________________

Free Windows Admin Tool Kit Click here and download it now
November 28th, 2012 6:48am

Interesting that my answer stood for almost two years before being shown to be incorrect, as noted in this thread.

The effect of the cancel button is to effectively not return any value. Thus the variable in question retains whatever its previous value was.

August 25th, 2014 2:28pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics