Search code examples
xmlvbacsvvmwarepowercli

Creating Virtual Machines using PowerCLI based on data from CSV File


I am attempting to find out how or whether it is possible to create a PowerCLI script that will handle creating Virtual Machines (VM's) within specific clusters based on a CSV file.

I have found some solutions that involve having PowerCLI read from XML files and I want to determine if CSV file data is also an option and if so, how to go about doing it.

Background: Users input the VM specification data into an Excel 'request' form, a VBA script is used to translate that data to a CSV file and I am wondering if it would be possible to have a PowerCLI script read from that resulting CSV files data to create the VM's with the specified values (to be reviewed prior to executing to ensure data is correct/relevant).

Thank you for any help you may provide


Solution

  • Received some help from the VMware Community site and was able to retrieve a simple script to create VMs with PowerCLI:

    #Specify path of .csv file to import VM settings
    $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.C_System)"