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
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
ForEach-Object -Process {
Set-VM -VM $_.OldName -Name $_.NewName -Confirm:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
hi tnx
i have created the CSV file which looks like this: (but with actual names)
OldName | NewName |
vm1 | newvm1 |
vm2 | newvm2 |
vm3 | newvm3 |
is this OK? asking because i ran the command and nothing happened
tnx in advance
Alex
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