VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Unable to get connect vcenter name

Hi,

I am trying to get connect vCenter name from the below script, vcenter name shows blank in the output

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

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

ForEach ($VM in Get-Folder Dev | Get-VM)

{

($VM.Extensiondata.Guest.Disk | Select @{N="Name";E={$VM.Name}},

@{N="vCenter";E={$VM_.Uid.Split('@')[1].Split(':')[0]}},

@{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

Please help..

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Are your vCenters in linked mode?
You can use the Server parameter, like this

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

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

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

        $VM.Extensiondata.Guest.Disk | Select @{N = "Name"; E = { $VM.Name } },

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

            @{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


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

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

Try with

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


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

That worked, but I am getting the VM names twice from both vcenter. how can I avoid getting duplicates

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Are your vCenters in linked mode?
You can use the Server parameter, like this

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

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

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

        $VM.Extensiondata.Guest.Disk | Select @{N = "Name"; E = { $VM.Name } },

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

            @{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


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

perfect....that worked Smiley Happy

Thank you very much!!!

Reply
0 Kudos