1

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

  • Do note that I am not familiar with PowerCLI, but if I understand correctly you want to launch your PowerCLI scripts from VBA code and input parameters from the csv files. If so you can have a look at various topics like [executing sheel scripts from VBA](http://stackoverflow.com/questions/17956651/execute-a-command-in-command-prompt-using-excel-vba) that could launch such a script, that could be an option. – Pierre Chevallier Nov 10 '16 at 13:34
  • Thanks for sending that over, Pierre. I will take a look at the link and see if that is applicable to what I am trying to do. The PowerCLI script doesn't necessarily have to be called by the VBA code, as we run that code separately on the Excel worksheet data to export the specific cells data into a CSV file. That functionality could certainly be useful going forward though. – NeedToKnowBasis22 Nov 10 '16 at 13:39
  • Your problem interests me so I had a quick look at some options, apparently you can [pass parameters with command line for your Script](https://communities.vmware.com/thread/340857?start=0&tstart=0) and hence pass them into your VBA code. Else there seems to be an `Import-Csv` solution for PowerCLI or [read from text file](https://communities.vmware.com/thread/434975?tstart=0) which is what is a _csv_ file in the first place . Hope it can help. – Pierre Chevallier Nov 10 '16 at 14:24

1 Answers1

1

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)"