次のように 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"):
では、最初のケースで確認プロンプトが表示されないのはなぜですか? 確認の好みが「高」の場合、影響が「高」のイベントが確認をトリガーするはずです。