我有以下代码:
$versionList = "Windows 2000","Windows XP","Windows Vista","Windows 7","Windows 8","Windows Server 2003","Windows Server 2008","Windows Server 2008 R2","Windows Server 2012","Windows Server 2012 R2"
for($i = 0;$i -ne 10;$i++){
$versionCheck = Get-ADComputer -Filter * -Property * | select OperatingSystem | where {$_.OperatingSystem -match $versionList[$i]}
if($i -eq 0){
Write-Host "Clients:" -for Green
}
if($i -eq 5){
Write-Host "Servers:" -for Green
}
Write-Host $versionList[$i] `t $($versionCheck.OperatingSystem).Count
}
这给出了以下输出:
Clients:
Windows 2000 0
Windows XP 0
Windows Vista 0
Windows 7 0
Windows 8 0
Servers:
Windows Server 2003 0
Windows Server 2008 0
Windows Server 2008 R2 0
Windows Server 2012 1
Windows Server 2012 R2 0
基于服务器的操作系统的数字排列得很好。客户不多。我通常会将其格式化为表格,但每次循环运行时都会更新变量,这会产生很多表格。我将如何正确格式化它?