VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Duplicate Values when querying from multiple vCenters

Hi,

I am getting duplicate values from exporting the information from multiple vcenters. Please help.

$vCenters = @(
"vcenter1"
"vcenter2"
)
Connect-viserver -Server $vCenters

$vmfreeInfo = Foreach ($vc in $global:DefaultVIServers)
{
ForEach ($VM in get-folder "Release" | Get-VM)
{
($VM.Extensiondata.Guest.Disk | Select @{N='vCenter';E={([uri]$VM.ExtensionData.Client.ServiceUrl).Host}},
@{N="Name";E={$VM.Name}},
@{N="IP Address";E={$VM.guest.IPAddress[0]}},
@{N="VM PowerState";E={@($VM.PowerState)}},
@{N="OS"; E={@($VM.guest.OSFullName)}},
@{N="Folder";E={$VM.Folder.Name}},
@{N="MountPoint";E={$_.DiskPath}},
@{N="Capacity(GB)";E={[math]::Round($_.Capacity/ 1GB)}},
@{N="FreeSpace(GB)";E={[math]::Round($_.FreeSpace / 1GB)}},
@{N="FreeSpace(%)";E={[math]::Round(((100* ($_.FreeSpace))/($_.Capacity)),0)}},
@{N="UsedSpace(GB)";E={[math]::Round(((($_.Capacity / 1GB))-($_.FreeSpace / 1GB)),0)}})
}
}
$vmfreeInfo | ft -auto

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could start by adding the Server parameter on the cmdlets.


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 start by adding the Server parameter on the cmdlets.


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Hi LucD,

I edited the below line as below. It worked.

ForEach ($VM in get-folder "Release" -server $vc | Get-VM -server $vc)

Thank you very much for your help 🙂

 

Tags (1)
Reply
0 Kudos