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
venter6x | app43 | 192.168.3.127 | PoweredOn Microsoft Windows Server 2016 or later (64-bit) Dev |
venter6x | app43 | 192.168.3.127 | PoweredOn Microsoft Windows Server 2016 or later (64-bit) Dev |
venter6x | app39 | 192.168.3.130 | PoweredOn Microsoft Windows Server 2016 or later (64-bit) Dev |
venter6x | app39 | 192.168.3.130 | PoweredOn Microsoft Windows Server 2016 or later (64-bit) Dev |
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
Are your vCenters working in linked mode?
What is in $global:defaultviservers?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Below is the output, two different vCenters
output
Name | Port User |
---- | ---- ---- |
venter0016x | 443 LOC\adm.ganapa |
venter6x | 443 LOC\adm.ganapa |
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
No, they are not in linked mode
Also when running again one vcenter, VM name still shows multiple times
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