VMware Cloud Community
jackc201110141
Contributor
Contributor
Jump to solution

powercli script to rename vm's from csv

Hello,

I need some help writing a script to rename vm's and change the network connection to the correct vlan, based on input of a csv file.  Only the vm display name in vcenter needs to be changed (vmdk's will be renamed aftwards by peforming a svmotion)

csv will look like this:

oldname,newname,tobevlan

vm1,tag-vm1,vlan4

vm2,tag-vm2,vlan7

vm3,tag-vm3,vlan4

I'm already using LucD's script to import vm's based on a csv.  Now I need to add this part the to script.  I need to import a large number of vm's place on a few datastores.  There are some vm's that don't need to be imported, so I use a csv to import only the needed one's.  After the registration of the vm's, they all need to be renamed and network connection should be changed.

Thanks for your help.

Regards,

Christophe

Reply
0 Kudos
26 Replies
jackc201110141
Contributor
Contributor
Jump to solution

when I use this:   $vms = Import-csv -Header VMXPath,oldname,newname,vlan D:\temp\import-vm3.csv -UseCulture

I don't get an error but the script doesn't do anything... Smiley Sad

Reply
0 Kudos
jackc201110141
Contributor
Contributor
Jump to solution

when i leave out the -UseCulture, it does work Smiley Happy

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Which PowerShell version are you running ? Do a

$psversiontable

The UseCulture parameter was introduced in PowerShell v2.


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

Reply
0 Kudos
jackc201110141
Contributor
Contributor
Jump to solution

Name                           Value
----                           -----
CLRVersion                     2.0.50727.5466
BuildVersion                   6.1.7601.17514
PSVersion                      2.0
WSManStackVersion              2.0
PSCompatibleVersions           {1.0, 2.0}
SerializationVersion           1.1.0.1
PSRemotingProtocolVersion      2.1

Reply
0 Kudos
jackc201110141
Contributor
Contributor
Jump to solution

when I run the whole script: everything works!

Vm's get in the CSV get registered,  they get their new display name and vlan with input from the CSV.

I just get one error message, but the script continue to run:

Get-VM : 22/03/2013 14:29:15    Get-VM        VM with name 'oldname' was not found using the specified filter(s).
At line:2 char:9

Reply
0 Kudos
jackc201110141
Contributor
Contributor
Jump to solution

LucD and Crad14 thanks for you help !!!

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You're welcome, but I'm still curious to know why the UseCulture parameter doesn't seem to work.


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

Reply
0 Kudos