I’ve been playing around with powershell yesterday. We needed to create over 100 VM’s and there’s no point in doing that all by hand. The customer provided us with a .csv file that contained specific info on these VM’s. It took me a while to figure out how to read the info.csv file and how to actually use it. But as always it’s actually fairly simple and that’s why I decided to write it down:
Before we even start, the CSV should be formatted as follows:
vmname,cluster
VM001,HA-DRS-Yellow-Bricks
Read the complete csv file into a variable:
$csv_info = Import-Csv c:\scripts\info.csv
For every line in the csv variable do something:
foreach ($line in $csv_info) {
write-host " This is virtual machine $($line.vmname) on cluster $($line.cluster)"
}
This line would print something like this:
This is virtual machine VM001 on cluster HA-DRS-Yellow-Bricks
As you noticed in the example above we used $line.vmname to get the name of the VM printed and $line.cluster for the cluster name, cool huh! BTW, Alan’s quick reference guide really helped me out!







Does this incorporate a template so each machine will be syspreped?
I have created a powershell that can do all that a long time ago, please see the following doc:
http://communities.vmware.com/docs/DOC-6972
I can deploy vm’s on cluster, resource pool or single esx host.
The script is a specific to my environment, but you can change it very easy.
Soon i will place an updated version, because i edited the script recently.
Yes my script does Stuart, but I’m not allowed to post the complete script. However as Rob states he created an awesome script that does about the same.
@Rob , where’s the fun in copy + paste?
@Duncan
I was just promoting my script. I am working on it right now, i added some new features and even better error handling. Soon i will have linux support to.
Thank you for this, it was the exact code I needed to get the data out of my CSV and into a useable state.
Is it possible to sellect only one system(VMname) from the list(.csv file) and create the corresponding line(cluster) ?
like if line.VMname = VM005