Last active
March 29, 2018 21:51
-
-
Save royashbrook/c1f68834d72864fa623057d1c388821e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$sb = { | |
(New-Object -ComObject Microsoft.Update.Session).CreateUpdateSearcher() | %{ | |
$_.QueryHistory(0, $_.GetTotalHistoryCount()) | | |
? resultcode -in 2,3 | | |
? operation -eq 1 | | |
select title,date -unique | | |
%{ [pscustomobject]$_ } | |
} | |
} | |
$s = "s1,s2,s3,s4".split(',') | |
$j = icm $s -sc $sb -as | |
$r = gjb|wjb|rcjb | |
$r| ft pscomputername,date,title |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#get data from the update service | |
$o = new-object -c microsoft.update.session | |
$s = $o.CreateupdateSearcher() | |
$u = @($s.Search("IsHidden=0 and IsInstalled=0").Updates) | |
$Updates | Select-Object Title | |
#or can look at history | |
$Session = New-Object -ComObject "Microsoft.Update.Session" | |
$Searcher = $Session.CreateUpdateSearcher() | |
$historyCount = $Searcher.GetTotalHistoryCount() | |
$historyEntries = $Searcher.QueryHistory(0, $historyCount) | |
$Result = foreach($historyEntry in $historyEntries){ | |
New-Object PSCustomObject -Property @{ | |
COMPUTERNAME = $env:COMPUTERNAME | |
Date = $historyEntry.Date | |
Operation = switch($historyEntry.operation) { | |
1 {"Installation"} | |
2 {"Uninstallation"} | |
3 {"Other"} | |
} | |
Status = switch($historyEntry.resultcode) { | |
1 {"In Progress"} | |
2 {"Succeeded"} | |
3 {"Succeeded With Errors"} | |
4 {"Failed"} | |
5 {"Aborted"} | |
} | |
#Update = IF($historyEntry.Title.tostring() -match "\(.*?\)"){$matches[0].replace('(','').replace(')','')} | |
Title = $historyEntry.Title | |
} | |
} | |
$Result | Where{$_.Date -gt (Get-Date).AddDays(-30 | |
)} | Sort-Object Date | ft * |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment