$? after a failed command

suggest change
Get-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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents