VMware Cloud Community
aatef6
Contributor
Contributor

Change VM Name and harddisk path directory and vmdk to reflect new VM name

Hello Experts,

I'm in the process of preparing a script to change some VMs names. I prepared the script and applied it on PowerCli to change VM names on the fly (VMs were powered on). However,  when i was checking the VM files (get-harddisk), i noticed that the VM files are still keeping the old VM names and it did not reflect the new VM name. I have performed a little bit of a research and i did find a few remedies for that but they all require the VM to be down.

so my first question, is there a way to change the VM name and its files names on the fly while the VM is powered on? If the change cannot be done on the fly and VMs must be powered off what is the easiest and cleanest way to do it?

I could see two possible solutions for it, one of them is to change the VM name and then try cold migration of the VM to another data store or another host and then move it back to the original host and this should trigger the VM to change its file names to reflect the new name. the second possible solution is to follow the steps of Renaming virtual machine files in-place using the console in this link (Renaming a virtual machine and its files in VMware ESXi and ESX (1029513) | VMware KB ). Your help is always appreciated. Thanks

Reply
0 Kudos
5 Replies
DZ1
Hot Shot
Hot Shot

If you have a license, performing a storage vMotion will change the file name. 

Reply
0 Kudos
aatef6
Contributor
Contributor

Unfortunately no i do not have vMotion

Reply
0 Kudos
LucD
Leadership
Leadership

You could use the Copy-DatastoreItem cmdlet.

Something similar to what I did in my HL Tools – Part 1 – Clone a VM without vCenter post, but you would remove the original files after the copy.


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

Reply
0 Kudos
aatef6
Contributor
Contributor

Thanks a lot LucD .. this approach might not need doing any cold-migration to the VM however it still needs the master VM to be powered off so it might not be on-the-fly change. Are you aware of any way to change the vm files on the fly or that's impossible? Thanks

Reply
0 Kudos
LucD
Leadership
Leadership

If you don't have svMotion option, no, unfortunately not.


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

Reply
0 Kudos