Skip to content

Instantly share code, notes, and snippets.

@PrateekKumarSingh
Created July 5, 2019 16:44
Show Gist options
  • Save PrateekKumarSingh/83f27a15c1f975325c89dee7507ed57c to your computer and use it in GitHub Desktop.
Save PrateekKumarSingh/83f27a15c1f975325c89dee7507ed57c to your computer and use it in GitHub Desktop.
$Error.count # empty automatic variable
# throwing an error when file doesn't exists
Get-Item C:\Data\nosuchfile.txt
$Error.count # one error record logged
# supressing the error
Get-Item C:\Data\nosuchfile.txt -ErrorAction SilentlyContinue
$Error.count # but still capturing the error
# supress the error but not logging it in $Error variable
Get-Item C:\Data\nosuchfile.txt -ErrorAction Ignore
$Error.count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment