Я хотел бы получить представление матрицы / сетки всех моих серверов с установленными исправлениями.Я запрашиваю каждый сервер и получаю список вроде этого:
host1, fix1
host1, fix2
host1, fix3
host2, fix1
host3, fix1
host3, fix2
Моя сетка в идеале должна выглядеть так:
HOSTS, fix1, fix2, fix3
host1, Yes, Yes, Yes
host2, Yes, No, No
host3, Yes, Yes, No
Я думаю, что я должен сделать это, создав несколько циклов, но обычно я делаюстрока, подобная этой:
$row = "" | Select Name, item1, item2
Однако в этом случае я не знаю количество элементов до запуска сценария.Как я могу изменить размер строки $ динамически?
***** РЕДАКТИРОВАТЬ ***** Создана эта версия сценария Матиасом Р. Джессеном:
$ListOfAllHotfixes = @()
$fixesOnHosts = @()
$totalview = @()
$hyplist = Get-SCVMHostCluster -Name "CLH-LGF-CTX" | Get-SCVMHost
foreach( $hyphost in $hyplist)
{
$hotfixlist = Get-HotFix -ComputerName $hyphost # Per host a list off installed hotfixes
Foreach( $hotfix in $hotfixlist)
{
# Create list of just hotfixes to compare to later on
$ListOfAllHotfixes += $hotfix.hotfixid
# Create rows of hotfixes per host
$Row = "" | Select hostname, hotfix
$row.hostname = $hotfix.PSComputerName
$row.hotfix = $hotfix.HotFixID
$FixesOnHosts += $row }
}
# $ListOfAllHotfixes is now filled with all fixes per host, let's make it unique on hotfixid
$ListOfAllHotfixes = ($ListOfAllHotfixes | Sort-Object -Unique)
# Result = $FixesOnHosts = all hosts and all their hotfixes
# Result = $ListOffAllHotfixes = unique list of the hotfixes
$HotfixesPerHost = @{}
foreach($Hotfix in $FixesOnHosts)
{
$HotfixesPerHost[$Hotfix.Hostname] += @($Hotfix.Hotfix)
write-host "Host = " $Hotfix.Hostname
write-host "Hotfix = " $hotfix.hotfix
}
foreach($HypHost in $HotfixesPerHost.Keys)
{
$Properties = [ordered]@{ Hostname = $HypHost }
foreach($Hotfix in $ListOfAllHotfixes)
{
$Properties[$Hotfix] = $HotfixesPerHost[$HypHost] -contains $Hotfix
}
[pscustomobject]$Properties
}
Однако результатэто так:
Hostname : VCDHYP636
KB2843630 : True
KB2868626 : True
KB2883200 : True
KB2887595 : True
KB2893294 : True
(25 строк исправлений)
Hostname : VCDHYP609
KB2843630 : False
KB2868626 : False
KB2883200 : False
KB2887595 : False
KB2893294 : False
KB2894852 : True
KB2894856 : True