Skip to content

ShouldProcess does not emit Verbose Output even if $VerbosePreference is set #12148

@JustinGrote

Description

@JustinGrote

Steps to reproduce

function Test-Whatif {
    [CmdletBinding(SupportsShouldProcess)]
    param (
        $String = 'Thing to do'
    )
    $target = 'Thing to Target'
    $VerbosePreference ='continue'
    if ($PSCmdlet.ShouldProcess($target,$string)){
        "Did $string to $target"
    }
}

Expected behavior

ShouldProcess would show Verbose output if $VerbosePreference is set either at the parent or in-function level

Actual behavior

Only works if -Verbose parameter is explicity specified on the cmdlet

image

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.0
PSEdition                      Core
GitCommitId                    7.0.0
OS                             Microsoft Windows 10.0.19041
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productKeepOpenThe bot will ignore these and not auto-closeUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions