Wednesday, March 23, 2016

PowerShell: Finding commands (functions) with Risk Mitigation capabilities

Yesterday I was talking to a workshop about implementing Risk Mitigation capabilities into your own Advanced Functions in PowerShell. This got me thinking about how to identify the commands that have that capability enabled. More importantly the configuration of the ConfirmImpact setting.

If you don't know PowerShell uses a number of inputs when determining how the Risk Mitigation capabilities are applied.
For the WhatIf capability it is purely the presence of the -WhatIf switch parameter.
For the Confirm capability it is a combination of the ConfirmImpact value in the [CmdLetBinding()] attribute and the $ConfirmPreference variable value. Or the presence of -Confirm parameter

The following command we show all commands with the RiskMitigation capability.
Get-Command | Where-Object {$PsItem.Parameters.Keys.Count -gt 0 -and $PsItem.Parameters.ContainsKey('WhatIf')}

We can extend this further to retrieve the ConfirmImpact value however this is not exposed through a Parameter on the command object and can only be retrieved from the source definition. Unfortunately for CmdLets this is not exposed as they are compiled. This will work though for Functions so you can check your own commands etc.

Get-Command -CommandType Function | `
   Where-Object {$PsItem.Parameters.Keys.Count -gt 0 -and $PsItem.Parameters.ContainsKey('WhatIf')} | `
   Select-Object -Property Name,CommandType,@{Name="Impact";Expression={[Regex]::Match($PSItem.Definition, "(ConfirmImpact='(?<impact>.{1,})'{1})").Groups["Impact"].Value}}

This pipeline command uses the RegEx type accelerator and Match static member but similar could be achieved with the -Match operator.

Legal Stuff: As always the contents of this blog is provided “as-is”. The information, opinions and views expressed are those of the author and do not necessarily state or reflect those of any other company with affiliation to the products discussed. This includes any URLs or Tools. The author does not accept any responsibility from the use of the information or tools mentioned within this blog, and recommends adequate evaluation against your own requirements to measure suitability.


  1. Kup hublot fałszywy zegarek, najlepsza replika breitling, u-boat italo fontana, repliki cartier , zegarki hublot replica, fałszywe zegarki breitling, replika montblanc, chodź tu kupić repliki zegarków uk, zegarki rolex fałszywe, repliki zegarków repliki, zegarki repliki tag heuer, zegarek omega, najtańsze fałszywe rolex, omega.
    repliki zegarków Rolex
    repliki zegarków Rolex

  2. Fake Cartier watches come in all the fake watches prominent Cartier styles: Tortue, Tank, Santos, Ballon, and replica cartier watchesBaignore to mention a few. These come in a wonderful number of gorgeous gents and womens designs. Our fake Swiss Cartier watches are exact forgeries of the genuine ones, down to the detailing that includes coloured knobs, diamonds encrusting, and stainless-steel cases. These specific replications . are great for showing your love for quality whether at the workplace or perhaps in a social setting.

  3. The Audemars Piguet Jules Audemarsfake watches collection commemorates one of the brand’s founders. The line is characterized by its traditional and timeless round cases and overall minimalist design. replica jules audemars watchesHowever, behind the simplicity of these watches is an array of impressive functions, such as tourbillons, moon phases, and chronographs. Designed with both men and women in mind, the Jules Audemars collection fully embodies both the range and restraint of the brand.

  4. High quality from a trust worthy replica raybans sunglasses here can offer you the best in high quality, including fake raybans clubmaster , etc.

  5. replica rolex watches are crafted from the finest raw materials and mini for watchassembled with scrupulous attention to detail. Every component is designed, developed and produced in-house to the most exacting standards.

  6. Moncler have been developing their ski-inspired apparel since founded in 1952, moncler jackets for sale popular for their luxe quilted down coats originally produced for extreme cold-weather conditions. cheap moncler parka Sportswear-inspired clothing combined with street-style provides practical and versatile daily-wear pieces including Moncler t-shirts and polos perfect under a lightweight jacket.

  7. OMEGA has been a world leader in advanced watch design since 1848. Over the years, cheap replica watchesthe brand has been widely celebrated for their durability and precision. replica omega watches has served as the official timekeepers of the Olympic Games for nearly a century. They also created the official watch of the space program and first watch to land on the moon. Buying an OMEGA watch is an excellent way to invest in a piece of history.

  8. Another Michele hit,Replica handbags the more structured Sylvie replica Gucci bags presents Gucci’s saddle-inspired red and green racing stripes – a house signature since the 1950s – in a fresh new light. Smooth leather and chunky hardware lends contemporary appeal to this instantly iconic Gucci bag.