Discovering High Impact Cmdlets

by Apr 1, 2015

All Versions

Cmdlets can declare how severe their impact is. Typically, cmdlets that make changes to the system that cannot be undone will have an “Impact Level” of “High”.

When you run such a cmdlet, PowerShell will automatically pop up a confirmation dialog to protect you from accidents. Confirmation dialogs will prevent you from running these cmdlets unattended, though.

To find out what the “Impact Level” of cmdlets is, here is a piece of code that dumps this information:

Get-Command -CommandType Cmdlet | 
  ForEach-Object { 
    $type = $_.ImplementingType
    if ($type -ne $null)
    {
      $type.GetCustomAttributes($true) | 
      Where-Object { $_.VerbName -ne $null } |
      Select-Object @{Name='Name'
      Expression={'{0}-{1}' -f $_.VerbName, $_.NounName}}, ConfirmImpact
    }
  } |
  Sort-Object ConfirmImpact -Descending

To view only cmdlets with an Impact Level of “High”, add a filter:

Get-Command -CommandType Cmdlet | 
  ForEach-Object { 
    $type = $_.ImplementingType
    if ($type -ne $null)
    {
      $type.GetCustomAttributes($true) | 
      Where-Object { $_.VerbName -ne $null } |
      Select-Object @{Name='Name'
      Expression={'{0}-{1}' -f $_.VerbName, $_.NounName}}, ConfirmImpact
    }
  } |
  Sort-Object ConfirmImpact -Descending |
  Where-Object { $_.ConfirmImpact -eq 'High' }

To run these cmdlets unattended and dismiss the automatic confirmation, make sure you add the -Confirm:$False parameter.

Twitter This Tip! ReTweet this Tip!