Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What version of PowerShell fixed "whatif" propagation?

Tags:

powershell

There are numerous questions relating to working around the fact that PowerShell did not propagate whatif to child functions. A comment on this answer even mentions a Connect issue that was logged, but the issue seems to have disappeared.

The issue certainly no longer exists in PowerShell 5, as this example outputs "Skipped!" as you would expect it would:

function Outer
{
    [CmdletBinding(SupportsShouldProcess=$true)]
    param()

    Inner
}

function Inner
{
    [CmdletBinding(SupportsShouldProcess=$true)]
    param()

    if ($PSCmdlet.ShouldProcess("Inner"))
    {
        Write-Host "Process!"
    }
    else
    {
        Write-Host "Skipped!"
    }
}

Outer -WhatIf

However, it's not clear when this was fixed. I can't find a changelog older than 5, which makes no mention of the issue. Does anyone know which version of PowerShell fixed this issue?

(The question may seem irrelevant, but it would help script/module authors choose an appropriate minimum PS version to run against)

like image 552
Richard Szalay Avatar asked Aug 30 '16 23:08

Richard Szalay


1 Answers

As the comments by @PetSerAl and @LachieWhite indicate it seems to be fixed since PowerShell 2.0.

The download link for the release notes of that version of the Windows Management Framework is unfortunately no longer working. It seems to be on Scribd, but I don't have an account. (Anyone?)

Unless you know for sure you have a lower version in production, I think it is safe to assume the switch is going to work as expected.

like image 108
marsze Avatar answered Oct 24 '22 13:10

marsze