I’ve created a function to remove old installed modules and have added SupportsShouldProcess to cmdletbinding. From my understanding the -WhatIf switch should be passed down to any native cmdlet that already supports -WhatIf with no need to add $PSCmdlet.ShouldProcess(). Uninstall-Module supports -WhatIf but when i run the below function with -WhatIf it still uninstalls the old modules. What gives?
Hi John,
I believe you still need to tell the shell that your function supports both -confirm and -whatif. The way you actually implement that support is to write conditional code around whatever dangerous stuff your cmdlet is planning to do
You need to specify the confirm impact. And, while -most- commands that support -whatif will “inherit” it, you may in some cases need to implement ShouldProcess() as indicated in the previous reply.