-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed
Labels
In-PRIndicates that a PR is out for the issueIndicates that a PR is out for the issueIssue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-ReviewedA Working Group has reviewed this and made a recommendationA Working Group has reviewed this and made a recommendation
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
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.0Visuals
No response
mattcargile
Metadata
Metadata
Assignees
Labels
In-PRIndicates that a PR is out for the issueIndicates that a PR is out for the issueIssue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-ReviewedA Working Group has reviewed this and made a recommendationA Working Group has reviewed this and made a recommendation