I had a strange problem when I had a different behavior when installing "Set-PSDebug -Trace 2".
I traced it to a switch statement that did not execute properly and was able to play it on PowerShell V3, but not on PowerShell V2 or Powershell V1 (works as expected)
Take the following simple function:
function DoTest { $result = "Switch Case Not Executed" $VendorName = "Microsoft" switch ($VendorName) { "Microsoft" { $result = "Switch Case Executed" } } Write-host "Switch: $($VendorName) -> $result"
}
Now run the following:
#Works as expected Set-PSDebug -Off; DoTest;
PosH V3 Results with PSDebug Tracing
DEBUG: 3+ Set-PSDebug -Trace 2; >>>> DoTest; DEBUG: 1+ function DoTest >>>> { DEBUG: ! CALL function 'DoTest' DEBUG: 2+ >>>> $result = "Switch Case Not Executed" DEBUG: ! SET $result = 'Switch Case Not Executed'. DEBUG: 3+ >>>> $VendorName = "Microsoft" DEBUG: ! SET $VendorName = 'Microsoft'. DEBUG: ! SET $switch = 'Microsoft'. DEBUG: 4+ switch ( >>>> $VendorName) DEBUG: ! SET $switch = ''. DEBUG: 9+ >>>> Write-host "Switch: $($VendorName) -> $result" DEBUG: 9+ Write-host "Switch: $( >>>> $VendorName) -> $result" Switch: Microsoft -> Switch Case Not Executed DEBUG: 11+ >>>> }
In version 3 of PoSH, even a debug trace indicates that the value is set, but seems to completely ignore the switch statement. I even tried Set-StrictMode and everything works fine. This is only when PSDebug tracing is enabled. Is this behavior expected?
switch-statement powershell
The unique paul smith
source share