ค้นหาเว็บไซต์

ข้อความยืนยัน


ต่อไปนี้เป็นข้อความยืนยันที่แตกต่างกันที่สามารถแสดงได้ ขึ้นอยู่กับตัวแปรของเมธอด System.Management.Automation.Cmdlet.ShouldProcess และ System.Management.Automation.Cmdlet.ShouldContinue ที่ถูกเรียก

มันเป็นสิ่งสำคัญ

สำหรับโค้ดตัวอย่างที่แสดงวิธีการขอการยืนยัน โปรดดูวิธีการขอการยืนยัน

การระบุทรัพยากร

คุณสามารถระบุทรัพยากรที่กำลังจะเปลี่ยนแปลงได้โดยการเรียกเมธอด System.Management.Automation.Cmdlet.Shouldprocess%2A?Displayproperty=Fullname ในกรณีนี้ คุณระบุทรัพยากรโดยใช้พารามิเตอร์ เป้าหมาย ของวิธีการ และการดำเนินการจะถูกเพิ่มโดย 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%2A?Displayproperty=Fullname ในกรณีนี้ คุณจัดหาทรัพยากรโดยใช้พารามิเตอร์ 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

บทความที่เกี่ยวข้อง