Skip to content

Instantly share code, notes, and snippets.

@poshcodebear
Created December 26, 2017 19:29
Show Gist options
  • Save poshcodebear/fa4eadccff90d7052c37506a9d9fb4c4 to your computer and use it in GitHub Desktop.
Save poshcodebear/fa4eadccff90d7052c37506a9d9fb4c4 to your computer and use it in GitHub Desktop.
Try/Catch/Finally example
try
{
$computers = Get-Content computers.txt -ErrorAction Stop
}
catch
{
"There was a problem opening the file; message: $($_.Exception.Message)" | Out-File -FilePath 'error.log' -Append
}
finally
{
Write-Host 'Tried to read computers file'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment