VM 和集群的详细信息

Details of VM and cluster

我有一个命令 t 从 VM 列表中获取集群详细信息。

ForEach ($VM in Get-Content C:\Temp\servers.txt)
{
Get-Cluster (Get-VM $vm).ComputerName     
} 

并且脚本的输出仅显示 VM 的集群详细信息,如下所示

Name
----
dhypervcl001
dhypervcl001
dhypervcl001

谁能告诉我,我怎样才能得到以下格式的输出,即服务器名和集群名

server1, dhypervcl001
server2, dhypervcl0011
server3, dhypervcl012

使用string.Format:

ForEach ($VM in Get-Content C:\Temp\servers.txt)
{
"{0},{1}" -f $vm, (Get-Cluster (Get-VM $vm).ComputerName)     
}

PSCustomObject:

ForEach ($VM in Get-Content C:\Temp\servers.txt)
{
$Row = "" | Select Server,Cluster
$Row.Server = $VM
$Row.Cluster = (Get-Cluster (Get-VM $vm).ComputerName) 
$Row
}