Automation

 View Only
  • 1.  VM names showing twice

    Posted Jan 24, 2020 12:15 PM

    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


  • 2.  RE: VM names showing twice

    Posted Jan 24, 2020 12:45 PM

    Are your vCenters working in linked mode?

    What is in $global:defaultviservers?



  • 3.  RE: VM names showing twice

    Posted Jan 24, 2020 12:52 PM

    LucD,

    Below is the output, two different vCenters

    output

    Name                       Port  User
    ----                       ----  ----
    venter0016x           443   LOC\adm.ganapa
    venter6x                443   LOC\adm.ganapa


  • 4.  RE: VM names showing twice

    Posted Jan 24, 2020 01:00 PM

    But are they in linked mode?

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



  • 5.  RE: VM names showing twice

    Posted Jan 24, 2020 01:10 PM

    No, they are not in linked mode

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



  • 6.  RE: VM names showing twice
    Best Answer

    Posted Jan 24, 2020 01:21 PM

    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 :smileyhappy: