VMware Cloud Community
Nagarjun111
Enthusiast
Enthusiast
Jump to solution

Finding VM & Adding vCenter details into the Output

Dear Experts,

We are using the below code (which is a part of a script) for searching a VM and its host details in our environment. It is working fine. However I would like to add vCenter details to it as we connect to multiple vCenters in that script.

Could you please modify the below code and let me know?

Get-VM -Name $VM | Select Name,Powerstate, NumCPU,MemoryGB,ResourcePool,Folder, @{N="Cluster";E={Get-Cluster -VM $_}}, `

@{N="ESXi Host";E={Get-VMHost -VM $_}},

@{N="Datastore";E={Get-Datastore -VM $_}}

#@{N="VC";E={$global:defaultviserver}}

#Disconnect-VIserver -Confirm $false

Current Output will be as below

Name         : XXXXXXXXXXX

PowerState   : PoweredOn

NumCpu       : 16

MemoryGB     : 64

ResourcePool : XXXXXXXXXXX

Folder       : XXXXXXXXXXX

Cluster      : XXXXXXXXXXX

ESXi Host    : XXXXXXXXXXX

Datastore    : XXXXXXXXXXX

Expected Output

Name         : XXXXXXXXXXX

PowerState   : PoweredOn

NumCpu       : 16

MemoryGB     : 64

ResourcePool : XXXXXXXXXXX

Folder       : XXXXXXXXXXX

Cluster      : XXXXXXXXXXX

ESXi Host    : XXXXXXXXXXX

Datastore    : XXXXXXXXXXX

vCenter    : 

Tags (2)
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could use

@{N = 'VC'; E = { ([uri]$_.ExtensionData.Client.ServiceUrl).Host } },


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

You could use

@{N = 'VC'; E = { ([uri]$_.ExtensionData.Client.ServiceUrl).Host } },


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

Reply
0 Kudos
Nagarjun111
Enthusiast
Enthusiast
Jump to solution

Hi LucD,

Thank you so much for quicker response and resolution.

I have updated my code to this and its working as expected. 🙂

Get-VM -Name $VM | Select Name,Powerstate, NumCPU,MemoryGB,ResourcePool,Folder, @{N="Cluster";E={Get-Cluster -VM $_}}, `

@{N="ESXi Host";E={Get-VMHost -VM $_}},

@{N="Datastore";E={Get-Datastore -VM $_}},

@{N ="vCenter";E={([uri]$_.ExtensionData.Client.ServiceUrl).Host}}

Reply
0 Kudos