$? after a failed command
suggest changeGet-Process -Name doesnotexist
Write-Host -Object "Was the last operation successful? $?"
$? contains the execution status of the last operation. It is $true if the last operation succeeded and $false if it failed. Get-Process writes a non-terminating error here, so the next statement still runs. The $? inside that string is the status of Get-Process.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents