- 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.
- Java EE 6 企業級應用開發教程
- 大學計算機應用基礎實踐教程
- Java異步編程實戰
- 零基礎玩轉區塊鏈
- Vue.js快跑:構建觸手可及的高性能Web應用
- Animate CC二維動畫設計與制作(微課版)
- Apache Spark Graph Processing
- JavaScript+Vue+React全程實例
- Unity Shader入門精要
- OpenShift在企業中的實踐:PaaS DevOps微服務(第2版)
- concrete5 Cookbook
- MongoDB,Express,Angular,and Node.js Fundamentals
- C語言程序設計
- Scala Functional Programming Patterns
- Appcelerator Titanium:Patterns and Best Practices