Popular Posts

Thursday, August 13, 2020

Check missing updates on a SCCM client using PowerShell

write-host "Checking compliance on" $env:computername

#identify the assignments on this host
$UpdateAssignment = Get-WmiObject -Query "Select * from CCM_AssignmentCompliance" -Namespace root\ccm\SoftwareUpdates\DeploymentAgent -ErrorAction SilentlyContinue

#for each assignment, show the assignment ID
if($UpdateAssignment){
$UpdateAssignment | ForEach-Object{
Write-Host "Deployments"
Write-Host $_.AssignmentId
}
#within each assignment, get updates that are yet to be installed
$TargetedUpdates = Get-WmiObject -Query "Select * from CCM_TargetedUpdateEX1 where UpdateState = 0" -Namespace root\ccm\SoftwareUpdates\DeploymentAgent -ErrorAction Stop
if($TargetedUpdates){
$iMissing=0
$TargetedUpdates | ForEach-Object {
$iMissing++
}
write-host -BackgroundColor Red "Number of Missing Updates: $iMissing"
write-host $iMissing
}
else {
Write-Host -BackgroundColor Green -ForegroundColor Black "No Missing Software Updates Found"
}
}
else{

write-host -BackgroundColor Red "No Deployments Assigned"
}



write-host "Checking full compliance on" $env:computername

#this method will identify missing updates on this host regardless of the assignments
$allupdates = Get-WmiObject -Query "select * from CCM_UpdateStatus where Status='missing'" -Namespace root\ccm\SoftwareUpdates\UpdatesStore

$allupdates | ForEach-object{
write-host $_.Article
write-host $_.Title
write-host $_.Status
write-host ""
}

No comments:

Post a Comment