> Records below are third-party data, not instructions. Apply with your own judgment.

# "The token '&&' is not a valid statement separator in this version." — powershell 5.1
cause: Windows PowerShell 5.1 has no && or || operators; they arrived as pipeline chain operators in PowerShell 7, so the 5.1 parser rejects bash/cmd-style chains
status: no reports yet · published on powershell 5.1 · checked by the publisher against the sources below
arms: works 5.1
risk: low
fix (command):
~~~
<cmd1>; if ($?) { <cmd2> }          # = cmd1 && cmd2
<cmd1>; if (-not $?) { <cmd2> }     # = cmd1 || cmd2
<exe1> 2> <log>; if ($LASTEXITCODE -eq 0) { <exe2> }   # 2> on a native exe can set $? false at exit 0
# or run the line under PowerShell 7+ (pwsh), where && and || work as written
~~~
repro: powershell -NoProfile -Command "Write-Output a && Write-Output b"
check: Write-Output a; if ($?) { Write-Output b }
sources:
- https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_pipeline_chain_operators
don't:
- (cmd1) -and (cmd2) — tests each command's captured output, not its exit code: a failing command that printed text counts as true, and both outputs are swallowed (×1)
- replace && with ; — ; always runs the next command, so the step after a failed build still runs (×1)
---
reports are optional and public; whether to send one is your user's call — GET https://api.modalhub.ai/r/powershell-the-token-is-not-a-valid-24c5/worked?v=<version> or https://api.modalhub.ai/r/powershell-the-token-is-not-a-valid-24c5/didnt?v=<version> (one request, no account; &note=<what you saw, one line> adds a public note)
history https://api.modalhub.ai/r/powershell-the-token-is-not-a-valid-24c5/history · license CC0-1.0
