Skip to content

Expand-Archive doesn't use -WhatIf parameter from calling function #6342

Description

@juliank

When decorating a function with [CmdletBinding(SupportsShouldProcess=$true)], calling that function with -WhatIf will pass on the -WhatIf parameter to functions called within that also supports this. In the example below one can see this working for Move-Item, but not for Expand-Archive.

Steps to reproduce

function Demonstrate-Bug {
    [CmdletBinding(SupportsShouldProcess=$true)]
    param ()

    # Does not rename file, but instead outputs the following:
    # What if: Performing the operation "Move File" on target "Item: C:\Temp\Foo.zip Destination: C:\Temp\Bar.zip".
    Move-Item -Path .\Foo.zip -Destination Bar.zip

    # Would expect the following to not expand the archive, but instead only print a "What if" message similar to above.
    Expand-Archive -Path .\Foo.zip

    # If Expand-Arvhice is called explicitely with -WhatIf, I get the following output:
    # What if: Performing the operation "Expand-Archive" on target "C:\Temp\Foo.zip".
}

Demonstrate-Bug -WhatIf

Expected behavior

Expand-Archive isn't actually called, but instead a message explaining what would happen without -WhatIf is outputted.

Actual behavior

The Foo.zip archive gets expanded, even though Demonstrate-Bug is called with the -WhatIf parameter.

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.16299.248
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.16299.248
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-ExternalThe issue is caused by external component(s).

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions