共用方式為


確認訊息

以下是根據 System.Management.Automation.Cmdlet.ShouldProcessSystem.Management.Automation.Cmdlet.ShouldContinue 方法而顯示的不同確認訊息。

這很重要

如需示範如何要求確認的範例程式代碼,請參閱 如何要求確認

指定資源

您可以呼叫 System.Management.Automation.Cmdlet.ShouldProcess 方法來指定即將變更的資源。 在此情況下,您會使用 方法的 target 參數來提供資源,而作業則由 Windows PowerShell 新增。 在下列訊息中,「MyResource」 文字是處理的資源,而作業是發出呼叫的命令名稱。

Confirm
Are you sure you want to perform this action?
Performing operation "Test-RequestConfirmationTemplate1" on Target "MyResource".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):

如果使用者選取 [是] [是][全部 確認要求] (如下列範例所示),則會呼叫 System.Management.Automation.Cmdlet.ShouldContinue 方法,這會導致顯示第二個確認訊息。

Confirm
Are you sure you want to perform this action?
Performing operation "Test-RequestConfirmationTemplate1" on Target "MyResource".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): y

Confirm
Continue with this operation?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"):

指定作業和資源

您可以呼叫 System.Management.Automation.Cmdlet.ShouldProcess 方法來指定即將變更的資源,以及命令即將執行的作業。 在此情況下,您會使用 target 參數提供資源,並使用 target 參數來提供作業。 在下列訊息中,「MyResource」 文字是處理的資源,而 「MyAction」 是要執行的作業。

Confirm
Are you sure you want to perform this action?
Performing operation "MyAction" on Target "MyResource".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):

如果使用者選取 [是] [是][全部 至上一則訊息,則會呼叫 System.Management.Automation.Cmdlet.ShouldContinue 方法,這會導致顯示第二個確認訊息。

Confirm
Are you sure you want to perform this action?
Performing operation "MyAction" on Target "MyResource".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): y

Confirm
Continue with this operation?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"):

另請參閱

撰寫 Windows PowerShell Cmdlet