KEMBAR78
Debug switch triggers $PSCmdlet.ShouldProcess prompt · Issue #16158 · PowerShell/PowerShell · GitHub
Skip to content

Debug switch triggers $PSCmdlet.ShouldProcess prompt #16158

@nmbell

Description

@nmbell

Prerequisites

Steps to reproduce

The function below has no debug output, so I would expect that the -Debug switch would have no effect, but it triggers the -Confirm prompt.

function Test-DebugWithConfirm
{
	[CmdletBinding(
	  SupportsShouldProcess = $true
	, ConfirmImpact         = 'Low'
	)]

	Param ()

	BEGIN
	{
		$confirmImpact = $MyInvocation.MyCommand.ScriptBlock.Attributes | Where-Object { $_ -is [System.Management.Automation.CmdletBindingAttribute] } | Select-Object -ExpandProperty ConfirmImpact
		Write-Host "`$confirmImpact    : $confirmImpact"
		Write-Host "`$ConfirmPreference: $ConfirmPreference"
		Write-Host "`$DebugPreference  : $DebugPreference"
	}

	PROCESS
	{
		If ($PSCmdlet.ShouldProcess('Doing the thing.','Proceed?','Ready to do the thing.'))
		{
			Write-Host 'Doing the thing.' -ForegroundColor Green
		}
	}

	END {}
}

Set the $DebugPreference variable:

PS C:\> $DebugPreference = 'Continue'
PS C:\> Test-DebugWithConfirm
$confirmImpact    : Low
$ConfirmPreference: High
$DebugPreference  : Continue
Doing the thing.

So far, so good. Now call with the -Debug switch:

PS C:\> $DebugPreference = 'SilentlyContinue'
PS C:\> Test-DebugWithConfirm -Debug
$confirmImpact    : Low
$ConfirmPreference: High
$DebugPreference  : Continue

Ready to do the thing.
Proceed?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): y
Doing the thing.

This time the -Confirm prompt appeared.

Expected behavior

Both examples above should behave the same (no Confirm prompt).

Actual behavior

The second example above generates a Confirm prompt.

Error details

No response

Environment data

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

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    In-PRIndicates that a PR is out for the issueIssue-BugIssue has been identified as a bug in the productUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-ReviewedA Working Group has reviewed this and made a recommendation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions