VMware Cloud Community
Pozitim
Contributor
Contributor
Jump to solution

Deploy VM from CSV file

Hi everyone !

I would like to deploy many VM from a .csv file. I know it is pretty basic but I don't get it to work... What did I do wrong ?

Here is my scrypt :


$list = Import-CSV C:\config1_new_vm.csv
write-Output $list

$vcenter_ip = "192.168.0.14"
Connect-VIServer -Server $vcenter_ip -User root -Password password

foreach ($line in $list)
    New-VM –Name $line.name –Host $line.host -Datastore $line.datastore -DiskMB $line.disk –MemoryMB $line.memory –NumCPU $line.cpu –GuestID         rhel5_64Guest –CD –Description "Linux RH5"
}

Here my .csv file :

2011-10-29_114608.png

The result is :

name;host;datastore;disk;memory;cpu

-----------------------------------

vm1;h1e0mudag-a.dc.infra.com;h1e0mudag-local-storage;200;512;1

vm2;h1e0mudag-a.dc.infra.com;h1e0mudag-local-storage;300;513;2


New-VM : Impossible de valider l'argument sur le paramètre « Name ». L'argument est null ou vide.

Because I'm French, the message is in French but for those who don't understand French, it basicaly means :

Impossible to validate the argument in the parameter "Name". The argument is Null or empty.

I don't understand... I can select lines of my csv file but can't get the colomns... Is New-VM –Name $line.name not right ?

Thanks for your answers.

Pozitim


0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try changing the line

$list = Import-CSV C:\config1_new_vm.csv

into

$list = Import-CSV C:\config1_new_vm.csv -UseCulture
By default PowerShell expects the separator in CSV files to be a comma.
From your output, it looks as if your regional settings defined the separator as semicolumn.
With the UseCulture switch the cmdlet will use the regional settings to determine the separator.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Try changing the line

$list = Import-CSV C:\config1_new_vm.csv

into

$list = Import-CSV C:\config1_new_vm.csv -UseCulture
By default PowerShell expects the separator in CSV files to be a comma.
From your output, it looks as if your regional settings defined the separator as semicolumn.
With the UseCulture switch the cmdlet will use the regional settings to determine the separator.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Pozitim
Contributor
Contributor
Jump to solution

Thanks so much, it's working ! Quick, clear and right answer !

0 Kudos