VMware Cloud Community
mohan_kumar_off
Contributor
Contributor
Jump to solution

bulk rename vm display name

Hi Team,

We understand using set-vm in powercli we could rename a vm display name and then perform@ storage vmotion, as a newbie in scripting is there an option to perform the same task in bulk,we have around 100 vms that needs vm display name changed. My thoughts are having two entries in a  single file (.csv) with old name and new name, how do I ensure for each vm name in the column, its corresponding new name is set . I am thinking foreach loop for it, however unable to get the syntax/ code right, please advise., thanks in advance for your support. LucD

Tags (2)
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The rename of the DisplayName can indeed be done with the Set-VM cmdlet.

But how do you plan to do the svMotion?

Is there a specific destination to which the VM can be moved?

The rename is a simple loop

# CSV has 2 columns

# oldname,newname

# vm1,newvm1

# vm2,newvm2


Import-Csv -Path .\rename.csv -UseCulture -PipelineVariable row |

ForEach-Object -Process {

    Get-VM -Name $row.oldname |

    Set-VM -Name $row.newname -Confirm:$false

}


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

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

The rename of the DisplayName can indeed be done with the Set-VM cmdlet.

But how do you plan to do the svMotion?

Is there a specific destination to which the VM can be moved?

The rename is a simple loop

# CSV has 2 columns

# oldname,newname

# vm1,newvm1

# vm2,newvm2


Import-Csv -Path .\rename.csv -UseCulture -PipelineVariable row |

ForEach-Object -Process {

    Get-VM -Name $row.oldname |

    Set-VM -Name $row.newname -Confirm:$false

}


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

Reply
0 Kudos
mohan_kumar_off
Contributor
Contributor
Jump to solution

You are awesome as always LucD

I am using move-vm in bulk to move these vms to a new datastore and then they remain in that location.

Thanks again for your support.

Reply
0 Kudos