Saturday 22 December 2012

Show-Exceptions.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script gets all the exceptions you can trap by PowerShell 
  4. .DESCRIPTION 
  5.     This script looks at all the loaded assemblies to get all 
  6.     the exceptions you can trap/catch using PowerShell. The 
  7.     display only covers those parts of the .NET framework are loaded. 
  8. .NOTES 
  9.     File Name  : Show-Exceptions.ps1 
  10.     Author     : Thomas Lee - tfl@psp.co.uk 
  11.     Requires   : PowerShell Version 2.0 
  12. .LINK 
  13.     This script posted to: 
  14.         http://www.pshscripts.blogspot.com 
  15. .EXAMPLE 
  16.     Psh> .\Show-Exceptions.ps1 -Summary 
  17.     In 69 loaded assemblies, you have 418 exceptions: 
  18.  
  19. .EXAMPLE 
  20.     Psh> .\Show-Exceptions.ps1 
  21.     In 69 loaded assemblies, you have 418 exceptions: 
  22.  
  23.     Name                     FullName                                                 
  24.     ----                     --------                                                 
  25.     _Exception               System.Runtime.InteropServices._Exception                
  26.     AbandonedMutexException  System.Threading.AbandonedMutexException                 
  27.     AccessViolationException System.AccessViolationException                      
  28.     ... 
  29.      
  30. #> 
  31.  
  32. [CMDLETBINDING()] 
  33. Param ( 
  34. [switch] $summary 
  35. #    Get all the exceptions 
  36. $assemblies = [System.AppDomain]::CurrentDomain.GetAssemblies() 
  37. $exceptions = $Assemblies | ForEach { 
  38.      $_.GetTypes() | where { $_.FullName -Match "System$filter.*Exception$" } } 
  39.  
  40. # Now display the numbers checking for summary flag 
  41. "In {0} loaded assemblies, you have {1} exceptions:" -f $assemblies.count, $exceptions.count 
  42. If (-not $summary) { 
  43. $Exceptions | sort name | format-table name, fullname 
Technorati Tags:

No comments: