Author Posts

March 23, 2015 at 8:39 am

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
       }
    }
  }
}


March 23, 2015 at 9:00 am

Have a look at the Join-Object function from the PowerShell blog: http://blogs.msdn.com/b/powershell/archive/2012/07/13/join-object.aspx

Just keep in mind that doing this in PowerShell can be pretty slow, and if you're working with large datasets you'd be better off putting the information into a database (possibly with indexes) and letting it handle the joins.

March 23, 2015 at 9:01 am

I made an adjustment and It is now working.

March 23, 2015 at 9:02 am

ok I will Thank you Dave

March 23, 2015 at 9:25 am

hey Dave The way i have it written its creating a lot of duplicate records do you know? This part is creating the dupes

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
       }
    }
  }
}

March 23, 2015 at 9:36 am

No idea. I'd need to see example data and the results that you're getting (and how that differs from what you expected to get.)