I am feeling surprised by the difference between two seemingly identical scripts.
first.ps1:
'A' if ($true) { 'B' } 'C'
second.ps1:
'A' if ($true) { 'B' } 'C'
Now open a CMD window, and run these scripts like this:
powershell – < first.ps1 powershell – < second.ps1
first produces:
A B C
while second produces just
A
This has to be a bug.
In the redirection under cmd.exe case, the function completes normally and correctly if the if and else blocks are individually all on one line:
But if either block is split up onto more than one line and that branch is taken, the script aborts with no warning/output.
I’d report this on the PowerShell feedback site (connect.microsoft.com).