我的代码在下面,并且做得很好。但是,我想让VM的列表说10个VM,然后启动另一个"列"在同一行。几乎就像制造子弹一样。某个群集可能包含近100个虚拟机,并且列出100个虚拟机可能会非常混乱,并且会造成眼睛疲劳。
这可能吗?
$a = "<style>"
$a = $a + "BODY{background-color:peachpuff;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}"
$a = $a + "</style>"
$array = @()
$clusters = Get-Cluster | sort Name
Foreach ($cluster in $clusters)
{
$hosts = get-cluster -name $cluster | get-vmhost
$gethosts = ($hosts.Name | % { (get-vmhost $_).Name;}) -join ';';
$gethosts = $gethosts.Replace(';',"`r`n")
$vms = get-cluster -name $cluster | get-vm
$getvms = ($vms.Name | % { (get-vm $_).Name;}) -join ';';
$getvms = $getvms.Replace(';',"`r`n")
$vmCount = get-cluster -name $cluster | select Name, @{N=“NumVM“;E={($_ | Get-VM).Count}}
$obj = New-Object PSObject
$obj | Add-Member -MemberType NoteProperty -Name "Cluster" -Value $cluster
$obj | Add-Member -MemberType NoteProperty -Name "Hosts" -Value $gethosts
$obj | Add-Member -MemberType NoteProperty -Name "Number of VMs" -Value $vmCount.NumVM
$obj | Add-Member -MemberType NoteProperty -Name "VMs" -Value $getvms
$array += $obj
}
$array |select Cluster, Hosts, "Number of VMs", VMs| ConvertTo-HTML -head $a| out-file c:\temp\test\ClusterInfo.html -force
在我目前的脚本中,VM基本上只是列出并且适合屏幕&#34;该行将根据需要进行调整。但是,是否有更好的方法可以更清晰地自动调整和列出VM?
感谢任何帮助!
答案 0 :(得分:1)
我建议保持原样,并定义一种具有交替行颜色的样式:
$a = @"
<style>
BODY {
background-color:peachpuff;
}
TABLE {
border-width: 1px;
border-style: solid;
border-color: black;
border-collapse: collapse;
}
TH {
border-width: 1px;
padding: 0px;
border-style: solid;
border-color: black;
background-color:thistle
}
TR:nth-child(odd) {
background-color: lightgray;
}
TR:nth-child(even) {
background-color: white;
}
TD {
border-width: 1px;
padding: 0px;
border-style: solid;
border-color: black;
background-color:palegoldenrod
}
</style>
"@