I am making a WSUS Report that consists of 2 different type’s of queries. I am saving both results to separate $variables. I am looking for a way to combine both variables by matching the comnputername . This is what I have so far
Import-Module UpdateServices
#Connect To WSUS
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer()
$Servers = ipcsv "C:\PS\CSVs\downstream.csv"
#get LastReported
$lastreport = foreach ($s in $Servers.server) {
#Remote Server
$DownStreamWsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer("$($s)",$False,'8530')
$DownStreamWsus.GetComputerTargets() |
? {
$_.RequestedTargetGroupName -eq 'General Workstations' -or
$_.RequestedTargetGroupName -eq 'Test Workstations' -or
$_.RequestedTargetGroupName -eq 'Voice Mail Workstations'
} | select IPAddress,FullDomainName,RequestedTargetGroupName,LastReportedStatusTime | sort FullDomainName -Descending
}
#-Requires both an update scope and a computer scope
$updateScope = New-Object Microsoft.UpdateServices.Administration.UpdateScope
$computerScope = New-Object Microsoft.UpdateServices.Administration.ComputerTargetScope
#get Counts
$counts =$wsus.GetSummariesPerComputerTarget($updateScope,$computerScope) | ForEach {
$object = [pscustomobject] @{
Computername = $wsus.GetComputerTarget($_.ComputerTargetID).FullDomainName
Installed = $_.Installedcount
Failed = $_.Failedcount
Downloaded = $_.DownloadedCount
NotInstalled = $_.NotInstalledCount
Unknown = $_.UnknownCount
PendingReboot = $_.InstalledPendingRebootCount
}
$object.pstypenames.insert(0,"wsus.clientupdate.statistics")
$object
}
#Build Object
foreach ($l in $lastreport){
foreach ($c in $counts){
if ($($l.FullDomainName) -match $($c.computername) ) {
[pscustomobject] @{
IP = $i.IPAddress
Computername = $l.FullDomainName
Group = $l.RequestedTargetGroupName
LastReported = $l. LastReportedStatusTime
Failed = $c.Failed
NotInstalled = $c.NotInstalled
PendingReboot = $c.PendingReboot
}
}
}
}