Get-Process -Name doesnotexist
Write-Host -Object "Was the last operation successful? $?"

Contains the execution status of the last operation. It contains TRUE if the last operation succeeded and FALSE if it failed.