- AWS Tools for PowerShell 6
- Ramesh Waghmare
- 255字
- 2021-07-15 17:09:14
Risk mitigation parameters
PowerShell has two risk mitigation parameters called WhatIf and Confirm. They are very useful for testing complicated scripts without risking the code running amok. By appending WhatIf and Confirm, you get a preview of what could have happened without risking the damage. Let's take a real-life example of a file deletion using a wildcard. Consider that there are some files, and you plan to delete them. But you want to ensure that you are deleting the right set of files that you intend to delete. Because you are using a wildcard, the consequences could be very serious. Hence, it is always prudent to ensure that you are not risking the run of the command. Lets assume that you want to remove file*.txt files from some directory; you can use WhatIf something like following:
PS C:\>Get-Childitem C:\somedata\file*.txt -Recurse | Remove-Item -WhatIf

In the example, we used file*.txt (with a wildcard), and the command did not make any permanent change when you appended the command with WhatIf. The command run is just letting us know that if you run it without WhatIf, it is going to delete all those five files. Likewise, you can use Confirm by appending at the end of the command to get a confirmation if the specific file can be deleted or not:
PS C:\>Get-Childitem C:\somedata\file*.txt -Recurse | Remove-Item -Confirm

These two risk mitigation parameters are really powerful when you start rolling out the script to hundreds of servers, and it will help to ease your anxiety a little bit.
- Boost程序庫完全開發指南:深入C++”準”標準庫(第5版)
- Fundamentals of Linux
- 在最好的年紀學Python:小學生趣味編程
- Mastering Adobe Captivate 2017(Fourth Edition)
- Maven Build Customization
- Amazon S3 Cookbook
- Julia Cookbook
- Mastering RStudio:Develop,Communicate,and Collaborate with R
- OpenCV 4計算機視覺項目實戰(原書第2版)
- 愛上micro:bit
- Advanced UFT 12 for Test Engineers Cookbook
- SwiftUI極簡開發
- Java EE實用教程
- 網絡綜合布線與組網實戰指南
- Mastering Magento Theme Design