VMware Cloud Community
carterrg
Contributor
Contributor
Jump to solution

get vCenter name for VM

Hi,

Is there a way to get the name of the vCenter that a VM is managed by, if I start with the VM name?

I have 2 vCenters joined in linked mode, and connect to them both at the same time when I run scripts. I would like to add a field in my output such as VMname, vCenter, VMhost, etc

I had an idea to track the parent folders; but seem to stop at datacenter.

thanks.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You can retrieve the vCenter Server name from the Uid property of the virtual machine object. Like this:

(Get-VM YourVMName).Uid.Split(":")[0].Split("@")[1]

In PowerCLI 4.1 you can extend the virtual machine object with a vCenterServer property. Like this:

New-VIProperty -Name vCenterServer -ObjectType VirtualMachine -Value {$Args[0].Uid.Split(":")[0].Split("@")[1]}
Get-vm YourVMName | Select-Object -Property Name,vCenterServer

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

2 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You can retrieve the vCenter Server name from the Uid property of the virtual machine object. Like this:

(Get-VM YourVMName).Uid.Split(":")[0].Split("@")[1]

In PowerCLI 4.1 you can extend the virtual machine object with a vCenterServer property. Like this:

New-VIProperty -Name vCenterServer -ObjectType VirtualMachine -Value {$Args[0].Uid.Split(":")[0].Split("@")[1]}
Get-vm YourVMName | Select-Object -Property Name,vCenterServer

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
LucD
Leadership
Leadership
Jump to solution

Note that this will only work in PowerCLI 4.1 which introduced the Uid property.

____________

Blog: LucD notes

Twitter: lucd22


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