VMware Cloud Community
alxta13
Contributor
Contributor

Rename multiple VM's using txt file

I am looking for a PowerShell/PowerCLI script/way to rename 180 (only the display name not the vmdk/vmx files) vm's located in txt file under C:\Temp\vmlist.txt.

Is there a way to do it better then running the below command multiple (180) times

set-vm Old-VM-NAME1 -name 'New-VM-Name1' -confirm:$false

set-vm Old-VM-NAME2 -name 'New-VM-Name2' -confirm:$false

set-vm Old-VM-NAME3 -name 'New-VM-Name3' -confirm:$false

0 Kudos
3 Replies
LucD
Leadership
Leadership

You didn't specify the layout of that .txt file.

But assume it is a CSV file with 2 columns.

Something like this

OldName,NewName

vm1,newvm1

vm2,newvm2

You could do

Import-Csv -Path C:\Temp\vmlist.csv -UseCulture |

ForEach-Object -Process {

   Set-VM -VM $_.OldName -Name $_.NewName -Confirm:$false

}


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

0 Kudos
alxta13
Contributor
Contributor

hi tnx

i have created the CSV file which looks like this: (but with actual names)

  

OldNameNewName
vm1newvm1
vm2newvm2
vm3newvm3

is this OK? asking because i ran the command and nothing happened

tnx in advance

Alex

0 Kudos
LucD
Leadership
Leadership

You should probably place commas between the column fields (see my example).

When you run

Import-Csv -Path C:\Temp\vmlist.csv -UseCulture

you should see the lines with the 2 properties on your screen


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

0 Kudos