0

I use this code to get lists but the output doesn't look like what I expect. I am running two queries, before each of which I am displaying the table name. But as a result, I get two table names and after them one general table, while I expect two tables with names in front of them.

Clear-Host
Import-Module VMware.VimAutomation.Core 
Write-Host "Clusters"
Get-Cluster | Select Name, Id, ParentId


Write-Host "Folders"
Get-Folder -Type HostAndCluster | Select Name, Id, ParentId

Result:

Clusters

Folders
Name               Id                                    ParentId               
----               --                                    --------               
LAB                ClusterComputeResource-domain-c837    Folder-group-h7        
LAB2               ClusterComputeResource-domain-c833    Folder-group-h7        
LAB3               ClusterComputeResource-domain-c15169  Folder-group-h7        
LAB                Folder-group-h4                       Datacenter-datacenter-2
LAB2               Folder-group-h1544                    Folder-group-h4        
LAB3               Folder-group-h94                      Folder-group-h4        

But waiting this result:

Clusters
Name               Id                                    ParentId               
----               --                                    --------               
LAB                ClusterComputeResource-domain-c837    Folder-group-h7        
LAB2               ClusterComputeResource-domain-c833    Folder-group-h7        
LAB3               ClusterComputeResource-domain-c15169  Folder-group-h7        

Folders
Name               Id                                    ParentId   
LAB                Folder-group-h4                       Datacenter-datacenter-2
LAB2               Folder-group-h1544                    Folder-group-h4        
LAB3               Folder-group-h94                      Folder-group-h4        

I tried to output data to variables and then display the contents of the variables, but the result does not change, I get one common table at the output. If I comment out the second query I still get the same result

Write-Host "Clusters"
Get-Cluster | Select Name, Id, ParentId

Write-Host "Folders"
#Get-Folder -Type HostAndCluster | Select Name, Id, ParentId

Result

Clusters

Folders
Name               Id                                    ParentId               
----               --                                    --------               
LAB                ClusterComputeResource-domain-c837    Folder-group-h7        
LAB2               ClusterComputeResource-domain-c833    Folder-group-h7        
LAB3               ClusterComputeResource-domain-c15169  Folder-group-h7      

First comes the name of the tables and only after that comes the contents of the list If you just run two queries, then the result of the output is one table

Get-Cluster | Select Name, Id, ParentId
Get-Folder -Type HostAndCluster | Select Name, Id, ParentId

Result

Name               Id                                    ParentId               
----               --                                    --------               
LAB                ClusterComputeResource-domain-c837    Folder-group-h7        
LAB2               ClusterComputeResource-domain-c833    Folder-group-h7        
LAB3               ClusterComputeResource-domain-c15169  Folder-group-h7        
LAB                Folder-group-h4                       Datacenter-datacenter-2
LAB2               Folder-group-h1544                    Folder-group-h4        
LAB3               Folder-group-h94                      Folder-group-h4    
Ujin
  • 1
  • In short: use explicit `Format-Table` calls to make sure separate tables will be shown. E. g. `Get-Cluster | Select Name, Id, ParentId | Format-Table` – zett42 Oct 24 '22 at 09:18

0 Answers0