-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmissingUpdates.ps1
More file actions
45 lines (35 loc) · 1.79 KB
/
missingUpdates.ps1
File metadata and controls
45 lines (35 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
###Script###
#Global
$hostname = [System.Net.Dns]::GetHostByName($env:computerName) | Select -ExpandProperty Hostname
$LastUpdate = Get-Date -Format "yyyy.MM.dd HH:mm:ss" (get-Hotfix | select InstalledON | sort { [datetime]$_.InstalledON } -desc| Select-Object -ExpandProperty InstalledOn -First 1)
$LogDate = (Get-Date -Format "yyyy.MM.dd HH:mm:ss")
$LastBootTime = Get-Date -Format "yyyy.MM.dd HH:mm:ss" (Get-WmiObject win32_operatingsystem | select @{LABEL=’LastBootUpTime’;EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}} | Select-Object -ExpandProperty LastBootUpTime )
$os = (Get-WmiObject -class Win32_OperatingSystem).Caption
$hostinfo = [pscustomobject]@{'hostname'=$hostname;'LastUpdated'= $LastUpdate;'LogDate'= (Get-Date -Format "yyyy.MM.dd HH:mm:ss");'LastBoot'=$LastBootTime;'os'=$os}
#Collect RAW Data
$UpdateSession = New-Object -ComObject Microsoft.Update.Session
$UpdateSearcher = $UpdateSession.CreateupdateSearcher()
$Updates1 = @($UpdateSearcher.Search("IsHidden=0 and IsInstalled=0").Updates)
#Prepare Data for Arra<y
$UpdTypes = $Updates1.Categories.Name.Split(“`n”)
$UpdTitle = $Updates1.Title.Split(“`n”)
$UpdKB = $Updates1.KBArticleIDs
$UpdRelDate = $Updates1.LastDeploymentChangeTime
# Combine Arrays
[int]$max = $UpdTitle.Count
$ResultsAll = @()
foreach ($update in $Updates1) {
$ResultsAll += (
[PSCustomObject]@{
UpdateType = $update.Categories[0].Name
Title = $update.Title
KBNo = $update.KBArticleIDs[0]
ReleaseDate = Get-Date -Format "yyyy.MM.dd HH:mm:ss" $update.LastDeploymentChangeTime
}
)
}
$Results = $ResultsAll | Where-Object {$_.UpdateType -ne "Drivers"}
$jsonBase = @{}
$jsonBase.Add("Data",$Results)
$jsonBase.Add("Hostinfo",$hostinfo)
$jsonBase = $jsonBase | ConvertTo-Json