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
Technology Tips and News
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
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 ____________________________________________________________________________
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.