Skip to content

Instantly share code, notes, and snippets.

@automationhaus
Last active December 13, 2016 18:11
Show Gist options
  • Save automationhaus/648af7d758f18f69d1f815072b4d85e9 to your computer and use it in GitHub Desktop.
Save automationhaus/648af7d758f18f69d1f815072b4d85e9 to your computer and use it in GitHub Desktop.
Simple Function to Create your Error Output in a Try Catch
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