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)