I'll have this 'updateScope' filtering to retrieve the list of updates from a single computer.
And I'm using 'LatestRevisionApproved', but when I run it I'm also getting some superceded Updates, that I'm not interested on it, because I know that computer will never apply.
I may add an additional filter by each update, but Is this setting the good one to filter SuperCeded Updates? Why is not working as I expect?
$updatescope = New-Object Microsoft.UpdateServices.Administration.UpdateScope
$updateScope.ApprovedStates = [Microsoft.UpdateServices.Administration.ApprovedStates]::LatestRevisionApproved # Includes updates whose latest revision is approved.
$updateScope.UpdateApprovalActions = [Microsoft.UpdateServices.Administration.UpdateApprovalActions]::Install
$updateScope.UpdateSources = [Microsoft.UpdateServices.Administration.UpdateSources]::MicrosoftUpdate;
$updatescope.ExcludedInstallationStates=@('NotApplicable','Installed')
$updatescope.ToCreationDate = (get-date).AddDays(-$days)
$wsus.GetComputerTargetbyName($computername)
$updatelist = $mycomputer.GetUpdateInstallationInfoPerUpdate($updateScope) | where {$_.GetUpdate().IsSuperseded -eq $False}
write-output "Number of Pending updates $($updatelist.count)"
"Search Range From: {0:dd-MMM-yyyy} To: {1:dd-MMM-yyyy} (-{2} Days)" -f $updatescope.FromCreationDate,$updatescope.ToCreationDate,$Days
foreach ($update in $updatelist ) {
$updateinfo=$update.Getupdate()
[pscustomobject][Ordered]@{
Status=$update.UpdateInstallationState
Approval=$update.UpdateApprovalAction
ArrivalDate=get-date $updateinfo.ArrivalDate -format dd-MMM-yyyy
# ApprovalTargetGroup=$update.GetUpdateApprovalTargetGroup().name
PublicationState=$Updateinfo.PublicationState # expired?
Approved=$updateinfo.isapproved
KB=$updateinfo | %{$_.KnowledgebaseArticles -join ","}
SuperSeded=$updateinfo.IsSuperseded
Declined=$updateinfo.IsDeclined
Title=$updateinfo.title
}
}
Regards