Book Image

AWS Tools for PowerShell 6

By : Ramesh Waghmare
Book Image

AWS Tools for PowerShell 6

By: Ramesh Waghmare

Overview of this book

AWS Tools for PowerShell 6 shows you exactly how to automate all the aspects of AWS. You can take advantage of the amazing power of the cloud, yet add powerful scripts and mechanisms to perform common tasks faster than ever before. This book expands on the Amazon documentation with real-world, useful examples and production-ready scripts to automate all the aspects of your new cloud platform. It will cover topics such as managing Windows with PowerShell, setting up security services, administering database services, and deploying and managing networking. You will also explore advanced topics such as PowerShell authoring techniques, and configuring and managing storage and content delivery. By the end of this book, you will be able to use Amazon Web Services to automate and manage Windows servers. You will also have gained a good understanding of automating the AWS infrastructure using simple coding.
Table of Contents (17 chapters)

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.