VMware Cloud Community
faherne_CTI
Enthusiast
Enthusiast
Jump to solution

List vcenter InstanceUUIDs

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?

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

A minimalistic version

Connect-viserver -Server (Get-Content C:\vcenterList.txt) | select Name,InstanceUuid

 


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

View solution in original post

6 Replies
faherne_CTI
Enthusiast
Enthusiast
Jump to solution

The following code outputs the correct data for a single vcenter:

$vcenter = Connect-viserver myvCenterServer

$vcenter.InstanceUuid

d322b019-58d4-4d6f-9f8b-d28695a716c0

Reply
0 Kudos
vijayrana968
Virtuoso
Virtuoso
Jump to solution

Try  Write-Host ($vcenter | select-object InstanceUuid | Out-String)

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

A minimalistic version

Connect-viserver -Server (Get-Content C:\vcenterList.txt) | select Name,InstanceUuid

 


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

vijayrana968
Virtuoso
Virtuoso
Jump to solution

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,

Reply
0 Kudos
faherne_CTI
Enthusiast
Enthusiast
Jump to solution

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)

}

Reply
0 Kudos
faherne_CTI
Enthusiast
Enthusiast
Jump to solution

That worked an absolute treat.

Thanks for taking the time to look into this problem.

Reply
0 Kudos