I'm very new to powershell, and I've been trying to figure this out using portions of code I've found, but to no avail.
I'm looking for a script to take the DNS hostname listed in VCenter for a given VM and rename the VM.
Eg.
Host01VM01 (as listed in Vcenter) - DNS name of "something.xyz.com". Rename VM to "something.xyz.com" in Vcenter.
To run the script only for a cluster called "MyCluster" you can do:
Get-Cluster "My Cluster" | Get-VM | ` Where-Object { $_.Guest.HostName } | ` ForEach-Object { Set-VM -VM $_ -Name $_.Guest.HostName -Confirm:$false }
This script will only work for VM's that have the VMware Tools installed and probably only for VM's that are powered on.
You can try:
Get-VM | ` Where-Object { $_.Guest.HostName } | ` ForEach-Object { Set-VM -VM $_ -Name $_.Guest.HostName -Confirm:$false }
Regards, Robert
Message was edited by: RvdNieuwendijk
Thanks for the quick reply.
When I run this I don't get any output, just returns to the powershell command line. I'm obviously doing something wrong...
Also - I should have included this in my original post, but I need to rename all the VM's within one cluster in VCenter, leaving the others untouched.
To run the script only for a cluster called "MyCluster" you can do:
Get-Cluster "My Cluster" | Get-VM | ` Where-Object { $_.Guest.HostName } | ` ForEach-Object { Set-VM -VM $_ -Name $_.Guest.HostName -Confirm:$false }
This script will only work for VM's that have the VMware Tools installed and probably only for VM's that are powered on.
Works perfectly. Thanks for your help.