VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

VM names showing twice

Hi,

Please help, I am seeing VM details twice in the output when connecting multiple vCenters

Script

Connect-viserver -Server (Get-Content .\VC_Info.txt) > $null

$VmInfo = Foreach ($vc in $global:DefaultVIServers) {

    ForEach ($VM in (Get-Folder -Name Universal-Dev -Server $vc | Get-VM -Server $vc)) {

        $VM.Extensiondata.Guest.Disk | Select @{N='vCenter'; E={([uri]$vm.ExtensionData.Client.ServiceUrl).Host}},

            @{N="Name";E={$VM.Name}},

            @{N = "IPAddress";E={$VM.guest.IPAddress[0]}},

            @{N = "VM PowerState";E={@($VM.PowerState)}},

            @{N = "Operating System";E={@($VM.guest.OSFullName)}},

            @{N = "Folder";E={$VM.Folder.Name}}

        }

    }

$VmInfo | ft -auto

disconnect-viserver -server * -force -confirm:$false

Output

venter6xapp43192.168.3.127PoweredOn Microsoft Windows Server 2016 or later (64-bit) Dev
venter6xapp43192.168.3.127PoweredOn Microsoft Windows Server 2016 or later (64-bit) Dev
venter6xapp39192.168.3.130PoweredOn Microsoft Windows Server 2016 or later (64-bit) Dev
venter6xapp39192.168.3.130PoweredOn Microsoft Windows Server 2016 or later (64-bit) Dev
0 Kudos
1 Solution

Accepted Solutions
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

I am able to fix by replacing this line

$VM.Extensiondata.Guest.Disk | Select @{N='vCenter'; E={([uri]$vm.ExtensionData.Client.ServiceUrl).Host}},

with

$VM | Select @{N='vCenter'; E={([uri]$vm.ExtensionData.Client.ServiceUrl).Host}},

Thanks for your help Smiley Happy

View solution in original post

0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

Are your vCenters working in linked mode?

What is in $global:defaultviservers?


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

Below is the output, two different vCenters

output

Name                       Port  User
----                       ----  ----
venter0016x           443   LOC\adm.ganapa
venter6x                443   LOC\adm.ganapa
0 Kudos
LucD
Leadership
Leadership
Jump to solution

But are they in linked mode?

Try connecting to only one of the 2 vCenters, and then run your script again.


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

No, they are not in linked mode

Also when running again one vcenter, VM name still shows multiple times

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

I am able to fix by replacing this line

$VM.Extensiondata.Guest.Disk | Select @{N='vCenter'; E={([uri]$vm.ExtensionData.Client.ServiceUrl).Host}},

with

$VM | Select @{N='vCenter'; E={([uri]$vm.ExtensionData.Client.ServiceUrl).Host}},

Thanks for your help Smiley Happy

0 Kudos