Honestly speaking, I’m in love with PowerCLI. I know that VMware admin cannot optimize his job without PowerCLI, but in my case it’s a higher level of scripting love. At first, I want to stress that my scripting experience started with Linux systems and its scripting languages. I have been in awe of how excellent PowerShell can be since I decided to simplify my work with Windows Servers. Of course VMware administration has enforced me to become friends with PowerShell. New cmdlets, new possibilities, and – last but not least – the best way for managing and configuring VMware vSphere and vCloud Director.
But that’s enough of private reflections. Let’s focus on more practical thing – how to get Windows VMs in the vCloudDirector. Sometimes you can face that problem. Probably if you participate in the Microsoft SPLA program or just want to know your Windows VMs. Of course you may want to know some basic information about linux systems. In that case, you only need to make some small modifications in my script. The rest will be the same, so you can read this post anyway. 🙂
How to get Windows VMs in vCloud Director
Below you have a simple script, which save all Windows VMs as the CSV file. You can choose one of the existing ways for getting Windows or create one on your own. Here you can list Windows from:
- the whole vCloud Director,
- only one of the Provider VDC,
- the whole vCloud Director excluding one Provider VDC.
I think these three methods are one of the most possible ways you can use. You only need to uncomment one of them and run the script.
As you can see there are tons of possibilities for changing and adding your own variables.
Modifying the script
If you want to add new columns with an additional data, you should focus on the two lines:
1 2 |
20 Add-Content $csvfile "VM,HostName,Status,GuestOSFullName,Cpu,Memory,Env,ProviderVdc" 46 $write = "$name, $guestName, $status, $guestos, $CPU, $RAM, $env, $providervdc" |
First of them add headers to the CSV file. It is very important if you want to have a clear file. You should add/remove headers with your necessities.
The second one (line number 46) is a variable which merge all variables into the one row. If you create a new variable above it and do not add to the $write, you “lost” your data in the CSV file.
And that’s all. Feel free to use and modify this script. Please remember that it was created for my usage, so it is possible that you will need to change it heavily. 🙂