PSCmdlet.ShouldProcess output verbose stream even when $VerbosePreference='Silen

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 5 months, 3 weeks ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #37219
    Profile photo of Bor

    I have just found very strong behavior of $PSCmdlet.ShouldProcess(). I want to have it in my advanced function (I want to use -Confirm and -WhatIf) but I don't want to see it's verbose stream. I want to see only my custom streams (Write-Verbose). Please do you have an idea what it reason that the function output it? How to disable it?

    Thank you,

    Function Set-SomeThing {
            DefaultParametersetName = 'Bla',
            SupportsShouldProcess = $true,
            PositionalBinding = $false,
            ConfirmImpact = 'Medium'
                Mandatory = $false,
                Position = 0,
                ParameterSetName = 'Bla'
            [string] $Bla,
                Mandatory = $false,
                ParameterSetName = 'Bla'
            [string] $Force
        Begin {
            # Default:  $VerbosePreference = 'SilentlyContinue'
            # -Verbose: $VerbosePreference = 'Continue'
        Process {
            Write-Verbose -Message 'Something that I want to see'
            $VerbosePreference = 'SilentlyContinue'
            $global:VerbosePreference = 'SilentlyContinue'
            $script:VerbosePreference = 'SilentlyContinue'
            if ($Force -or $PSCmdlet.ShouldProcess('I do NOT want to see this', 'Action')) {
        End {
    Set-SomeThing -Verbose
    VERBOSE: Something that I want to see
    VERBOSE: Performing the operation "Action" on target "I do NOT want to see this".
    Profile photo of Don Jones
    Don Jones

    That's a hardcoded behavior – you can't work around that.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.