Here's an example I uncovered at my day job which saved me a lot of time and tedium.
The Storage team asked me to get disk information from a cluster pair. What they wanted was for me to run the following command at the command line:
mpclaim -s -d #
Where '#' was the number of the disk. The two cluster nodes have 18 disks each, so that would involve running that command 36 times.
Pfft on that. PowerShell to the rescue.
First, I created an array and filled it with the numbers 0 through 17, the actual disk numbers:
$array = ( 0..17 )
Then I used a Foreach loop to loop through the 'mpclaim' command:
Foreach ($unit in $array) {
mpclaim -s -d $unit | Out-File C:\Temp\mpio.txt -Append
}
Essentially, one by one, each number in the array gets assigned to the variable $unit, then plugged into the 'mpclaim' command. The output is piped to a text file using Out-File, and since I added the -Append parameter, the last results are added to the end of the file. Otherwise, the previous results would have been overwritten.
The amount of time it took for PowerShell to put my data into one neat text file to send to the Storage team? Two seconds. (I counted.)
No comments:
Post a Comment