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 :
You could use
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You could use
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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}}