PowerShell Automatic Variables $?


Contains status of the last operation. When there is no error, it is set to True:

PS C:\> Write-Host "Hello"
PS C:\> $?

If there is some error, it is set to False:

PS C:\> wrt-host
wrt-host : The term 'wrt-host' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ wrt-host
+ ~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (wrt-host:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\> $?