VMware Cloud Community
TheVMinator
Expert
Expert
Jump to solution

Renaming VMs

Howa would I cycle through a group of VMs and rename them based on their old name?  For example I have 20 VMs named

vm1

vm2, etc.

and I want to rename them to

vm1-old

vm2-old, etc.

doing something like

get-vm vm* | set-vm -name ($_.name+"-old")

This doesn't work quite right however

Thanks

0 Kudos
1 Solution

Accepted Solutions
mattboren
Expert
Expert
Jump to solution

Hello, TheVMinator-

You were pretty close, just needed to add a Foreach-Object loop and operate on each VM returned from Get-VM like so:

Get-VM vm* | %{Set-VM -VM $_ -Name "$($_.Name)-old" -Confirm:$false -WhatIf}

Note that I left the -WhatIf parameter on there so that when you run this, it just shows you what it would do.  To actually rename the VMs, just take out the -WhatIf.

View solution in original post

0 Kudos
2 Replies
mattboren
Expert
Expert
Jump to solution

Hello, TheVMinator-

You were pretty close, just needed to add a Foreach-Object loop and operate on each VM returned from Get-VM like so:

Get-VM vm* | %{Set-VM -VM $_ -Name "$($_.Name)-old" -Confirm:$false -WhatIf}

Note that I left the -WhatIf parameter on there so that when you run this, it just shows you what it would do.  To actually rename the VMs, just take out the -WhatIf.

0 Kudos
TheVMinator
Expert
Expert
Jump to solution

OK that worked - much appreciated.

0 Kudos