Last active
December 13, 2016 18:11
-
-
Save automationhaus/648af7d758f18f69d1f815072b4d85e9 to your computer and use it in GitHub Desktop.
Simple Function to Create your Error Output in a Try Catch
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
function Get-Catch | |
{ | |
<# | |
.SYNOPSIS | |
Allows you to use a single line of code for your catch | |
.DESCRIPTION | |
Creates consistent repeatable error output in your try / catch | |
.EXAMPLE | |
try { Get-Process | ?{$_.ProcessName -match "w3wp"} } catch { Get-Catch } | |
.LINK | |
https://automation.haus/simple-function-display-error-messages-try-catch | |
#> | |
$ErrorMessage = $_.Exception.Message | |
#Regarding Write-Tee https://gist.github.com/amesritter/6d239d7510f7784757140f82242b3861 | |
Write-Tee "[!] $ErrorMessage" | |
$Script:Outcome = "failed" | |
$Script:Color = "Red" | |
$Script:E++ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment