VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Unable to get correct vcenter name when querying from multiple vcenter

Hi,

I am unable to get the correct vCenter and VM details when querying VMs from multiple vcenters.

I am getting same VM Names for all vCenters

Please help

$vCenters = "myvcenter1","myvcenter2"
Connect-viserver -Server $vCenters

#Script
$out3 = $global:defaultviservers |
ForEach-Object -Process {
$vc = $_
Get-VM | Where-Object {$_.PowerState -eq 'PoweredOn' -and $_.extensiondata.config.createDate -ge (Get-Date).AddDays(-1)} |
Sort -Property CreatedTime -Descending |
Select @{N='vCenter';E={([System.Uri]$vc.ServiceUri.AbsoluteUri).Host}},
Folder,
@{N="VM Name";E={$_.Name}},
@{N="IPAddr";E={@($_.guest.IPAddress[0])}}, NumCPU, MemoryGB,
@{N="Used_HDD(GB)";E={[math]::round($_.UsedSpaceGB)}},
@{N="OS";E={$_.Guest.OSFullName}},
@{N="CreateDate";E={$_.extensiondata.config.createDate}}
}
$out3 | ft -auto

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You have to add the Server parameter on the Get-VM cmdlet

        Get-VM -Server $vc | Where-Object { $_.PowerState -eq 'PoweredOn' -and $_.extensiondata.config.createDate -ge (Get-Date).AddDays(-1) } |


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 have to add the Server parameter on the Get-VM cmdlet

        Get-VM -Server $vc | Where-Object { $_.PowerState -eq 'PoweredOn' -and $_.extensiondata.config.createDate -ge (Get-Date).AddDays(-1) } |


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Thanks for the quick help...that worked :slightly_smiling_face:

Reply
0 Kudos