Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Frustrations with "WhatIf" => Cascaded failures

$
0
0

I am building some CMDLets and adding "WhatIf" processing to them.

When I run a complex script with $WhatIfPreference = $True, I get cascaded failures.

So "New-Item" on "IIS:\Sites\ABC" is properly handled by Whatif.

But then the next several lines try to perform "Set-ItemProperty" on "IIS:\Sites\ABC" and they receive an error "Cannot find path 'IIS:\Sites\ABC' "

I have similar problems with "New-WebBinding".

I perceive this will become a constant battle.

I have already thought of some work arounds:

 

  • Put my own If ($PsCMDLet.ShouldProcess) blocks around the Set-ItemProperty CMDLets
    => Messy code - one per Set-ItemProperty if I want to see data on screen for each one
  • Use "Test-Path" to not run the CMDLets
    => hides the intent of the script.  Extra logic code required just to clean up WhatIf processing.
However, I am NOT so interested in work arounds as:
  • Is there a more built-in way of handling these cascaded failures? (Like a way to skip CMDLet existence checks when in "WhatIf" mode)
  • Has anyone had other *similar* frustrations when trying to use "WhatIf" for long or complex scripts that I haven't hit yet.
  • Has anyone else abandoned a comprehensive "whatif" implementation due to such challenges?
Thanks,
D.

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles