I'm playing with PowerShell and I've encountered a crash that I can easily reproduce on my computer.
I'm not sure if the code is correct. However, running the following piece makes powershell.exe
and powershell_ise.exe
crash. I guess that my use of if ( $? = $false )
is wrong, but crash should not happen in such case. Removing If
statement helps to avoid the crash.
Is there anything I'm missing?
I'm running Windows 10 Pro and PowerShell 5.1.14393.206.
Update 1
OK, thanks to @Martin I know that I mistakenly used =
instead of -eq
. But why this crash happens?
Update 2
Filed a bug report to PowerShell UserVoice: https://windowsserver.uservoice.com/forums/301869-powershell/suggestions/16977433-assigning-a-value-to-false-crashes
Update 3
It seems to be a known bug: https://github.com/PowerShell/PowerShell/issues/2243 that should be fixed soon https://github.com/PowerShell/PowerShell/pull/2320
Test-Path "C:\test"
if ( $? = $false ) {
Out-Host "Hello World"
}
Fault bucket 127386360339, type 5
Event Name: PowerShell
Response: Not available
Cab Id: 0
Problem signature:
P1: powershell.exe
P2: 10.0.14393.206
P3: stem.Management.Automation.PSInvalidCast
P4: stem.Management.Automation.PSInvalidCast
P5: ation.LanguagePrimitives.ThrowInvalidCastException
P6: ation.LanguagePrimitives.ThrowInvalidCastException
P7: Pipeli..ution Thread
P8:
P9:
P10:
Your code is wrong. You are assigning $false
to the question mark variable which is a read-only variable. You probably want to replace the =
with -eq
:
Test-Path "C:\test"
if ( $? -eq $false ) {
Out-Host "Hello World"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With