Created
December 26, 2017 19:29
-
-
Save poshcodebear/fa4eadccff90d7052c37506a9d9fb4c4 to your computer and use it in GitHub Desktop.
Try/Catch/Finally example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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