You will have to provide an ESXi server on the New-VM as well.
Then you could do something like this
Import-Csv C:\list.csv -UseCulture | %{ New-VM -Name $_.Name -VMHost $esx -Datastore $_.Datastore -DiskGB $_.DiskSize -GuestId "windows7Server64Guest"
}
Note that the GuestId requires a value from the VirtualMachineGuestOSIdentiefier enumeration.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It would be handier if the disksizes are on the same row in the CSV.
Name,Datastore,DiskSize1,DiskSize2,DiskSize3
VM1,ds1,10,20,25
VM2,ds1,10,20,0
Then you could do
Import-Csv C:\list.csv -UseCulture | %{ New-VM -Name $_.Name -Datastore $_.Datastore -DiskGB $_.DiskSize1,$_.DiskSize2,$_.DiskSize3 -GuestId "windows7Server64Guest"
}
If the DiskSize is 0, there will be no harddisk created
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc
What if I use wildcard for my datastore? will the code you provide work?
Name,Datastore,DiskSize1,DiskSize2,DiskSize3
VM1,ds1*,10,20,25
VM2,ds1*,10,20,0
Import-Csv C:\list.csv -UseCulture | %{
New-VM -Name $_.Name -Datastore $_.Datastore -DiskGB $_.DiskSize1,$_.DiskSize2,$_.DiskSize3 -GuestId "windows7Server64Guest"
}
No, the Datastore parameter expects a single value.
But you can use masking with a small change. Something like thisfor example
Import-Csv C:\list.csv -UseCulture | %{ New-VM -Name $_.Name -Datastore (Get-Datastore $_.Datastore | Get-Random) -DiskGB $_.DiskSize1,$_.DiskSize2,$_.DiskSize3 -GuestId "windows7Server64Guest"
}
The new VM will be placed on a randomly chosen datastore from the masked specs you give in the CSV.
But if you want to do this why don't you set up a datastorecluster (SDRS) ?
You can pass the datastorecluster name on the Datastore parameter and then SDRS will chose a datastore from the datastorecluster and also take into account the available free space.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference