Skip to content

Instantly share code, notes, and snippets.

@mattmcnabb
Created August 23, 2016 02:04
Show Gist options
  • Save mattmcnabb/9683a5ca0af21e5415d45d3611e7604b to your computer and use it in GitHub Desktop.
Save mattmcnabb/9683a5ca0af21e5415d45d3611e7604b to your computer and use it in GitHub Desktop.
Blog_Removing-Error-entries-in-powershell-functions
try
{
$Variables = Get-Variable -Scope Global -ErrorAction Stop
foreach ($Variable in $Variables)
{
$VarName = $Variable.Name
$Value = Invoke-Expression "`$$VarName"
$TypeName = $Value.PSObject.TypeNames[0]
if ($TypeName -eq 'My.Type') {$Value}
}
}
catch [System.Management.Automation.RuntimeException]{$Error.RemoveAt(0)}
catch [System.Management.Automation.RuntimeException]{$Global:Error.RemoveAt(0)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment