VMware Cloud Community
NeedToKnowBasis
Enthusiast
Enthusiast

Re: Creating Virtual Machines using PowerCLI based on data from CSV file

The examples provided seems to handle the VM name and the associated cluster; are there any available examples that I could look at that would allow me to specify the following information when creating the VM:

-Name (sometimes there multiple VM names associated with the same config information below - is there a way to write the PowerCLI code to handle multiple names while still using the same values?)

-VLAN number

-Number of vCPU

-RAM (GB)

-Memory per VM (GB): example c:\ 50, d:\ 40

Thank you for any information you may provide,

Matt

1 Reply
vXav
Expert
Expert

Not tested but here goes

$CSVPath = "C:\NewVMList.csv"

$CSVFILE = Import-CSV $CSVPath

$VMhost = Get-vmhost "$($CSVFile.VMHost)"

$PortGroup = Get-VirtualPortgroup -name "$($CSVFile.VLAN)" -VMhost $VMhost

New-VM -Name "$($CSVFile.name)" -MemoryGB "$($CSVFile.MemoryGB)" -NumCPU "$($CSVFile.NumCPU)" -portgroup $Portgroup -DiskGB "$($CSVFile.DiskGB)"