- AWS Tools for PowerShell 6
- Ramesh Waghmare
- 245字
- 2021-07-15 17:09:14
Building parameterized script
When you start building script for automation that can be used by yourself and others repeatedly for doing some task, building parameterized script is the key. In PowerShell, it is very easy to build the parameterized script using just a simple param keyword in the script file. You may have solved the problem using individual cmdlets, and you now want that one to be used repeatedly for building an automation. Let's review the following script for a better understanding of using parameters:

I created a file called DiskInfo.ps1 in the D:\scripts directory. This script provides you with free GB available on the drive that you pass to this script. I am using Get-CimInstance to get me the computer name and free GB. The param keyword at the top of the script can be seen. You might just need to get a feeling of writing that syntax and nothing more. To make the drive letter mandatory, I used a keyword called Mandatory=$true. Once you saved the file, the script can be run as follows:
PS :\D>.\DiskInfo.ps1 -Drive C:
The beauty of the script is that when you start hitting the tab after the script name on the command prompt, it starts displaying you the parameters that can be passed to the script, which is amazing. This is the way you start building a new set of cmdlets for you. There is nothing else that needs to be done to build your own cmdlets.
- DevOps:軟件架構(gòu)師行動(dòng)指南
- Mastering Adobe Captivate 2017(Fourth Edition)
- Magento 2 Theme Design(Second Edition)
- Java 9 Programming Blueprints
- OpenStack Cloud Computing Cookbook(Fourth Edition)
- Mastering Scientific Computing with R
- Flash CS6中文版應(yīng)用教程(第三版)
- FLL+WRO樂(lè)高機(jī)器人競(jìng)賽教程:機(jī)械、巡線與PID
- PHP+MySQL網(wǎng)站開發(fā)項(xiàng)目式教程
- Learn React with TypeScript 3
- 0 bug:C/C++商用工程之道
- HTML+CSS+JavaScript網(wǎng)頁(yè)制作:從入門到精通(第4版)
- INSTANT LESS CSS Preprocessor How-to
- 前端程序員面試算法寶典
- Game Development Patterns and Best Practices