我这样创建了 Test-ConfirmImpact.ps1:
[CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact="High")]
Param (
$Test = 1
)
New-Item -ItemType Directory -Path ".\Test"
请注意以下事项:
PS > $ConfirmPreference
High
PS > .\Test-ConfirmImpact.ps1
Directory: \\afgfile02\users\radams\scripts\PowerShell
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 8/14/2013 12:34 PM Test
PS > $ConfirmPreference = "Medium"
PS > Remove-Item ".\Test"
Confirm
Are you sure you want to perform this action?
Performing operation "Remove Directory" on Target ".\Test".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): y
PS > .\Test-ConfirmImpact.ps1
Confirm
Are you sure you want to perform this action?
Performing operation "Create directory" on Target "Destination: \.Test".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):
那么,为什么我在第一种情况下没有收到确认提示呢?我希望如果我的确认偏好是“高”,那么具有“高”影响的事件应该触发确认。