Create new vms with a template with a csv. Possible?

Posted by EdConde on Server Fault See other posts from Server Fault or by EdConde
Published on 2010-03-17T11:02:11Z Indexed on 2010/03/17 11:11 UTC
Read the original article Hit count: 170

Filed under:
|
|

I am new to Powershell and Powercli... but i manager few ESX environments and really would like to do as much as possible via powershell. I am trying to do as much as i can via Powershell. On with the help I need:

I used this one liner to create VMs from templates. But the problem is there has to be some user input after each new VM is created. New-VM name -Template template -VMHost VMHost -Datastore Datastore

What i would like to do is be able to import via CSV the name of the new vm, the template to use, the host to put the new vm and the datastore all from a CSV. I don't know if it is as easy as below, but i kept getting errors.

Import-Csv "C:\powershell\Data\VM2Create.csv" | Foreach-object{

New-VM $.name -Template $.template -VMHost $.VMHost -Datastore $.Datastore}

I know there some () or {} or possibly | that need... just don't know where to put them...

The csv i think would look like this:

name, template, vmhost, datastore

Any help or thoughts would be much appreciated...

© Server Fault or respective owner

Related posts about powershell

Related posts about vmware-vsphere