I want to read in a textfile containing a list of vCenter 6.0 servers then output said vCenter server's InstanceUuid's.
My code so far is:
$vCenterList = Get-Content C:\vcenterList.txt
Foreach ($vCenter in $vCenterList) {
Connect-viserver $vCenter
Write-Host $vcenter.InstanceUuid
}
I see the out of vCenter connections, but the "Write-Host $vcenter.InstanceUuid" outputs a blank line for each vCenter.
Any ideas what I'm doing wrong, or suggestions for alternative code options?
A minimalistic version
Connect-viserver -Server (Get-Content C:\vcenterList.txt) | select Name,InstanceUuid
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The following code outputs the correct data for a single vcenter:
$vcenter = Connect-viserver myvCenterServer
$vcenter.InstanceUuid
d322b019-58d4-4d6f-9f8b-d28695a716c0
Try Write-Host ($vcenter | select-object InstanceUuid | Out-String)
A minimalistic version
Connect-viserver -Server (Get-Content C:\vcenterList.txt) | select Name,InstanceUuid
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
My bad, it will be Write-Host $vcenter."Name","InstanceUuid"
But it doesn't make sense to keep it long, as LucD provided one-liner simple and straight,
Thanks for your response.
I tried modifying my code with your line, but Uuid was still coming out blank.
$vCenterList = Get-Content C:\vcenterList.txt
Foreach ($vCenter in $vCenterList) {
Connect-viserver $vCenter
Write-Host ($vcenter | select-object InstanceUuid | Out-String)
}
That worked an absolute treat.
Thanks for taking the time to look into this problem.