-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWindowsUpdateManagement.psm1
More file actions
71 lines (57 loc) · 1.96 KB
/
WindowsUpdateManagement.psm1
File metadata and controls
71 lines (57 loc) · 1.96 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# WindowsUpdateManagement Module
# Provides functions for managing Windows Updates
function Get-WindowsUpdateServiceInfo {
[CmdletBinding()]
param()
try {
$MUSM = New-Object -ComObject "Microsoft.Update.ServiceManager"
$MUSM.Services
}
catch {
Write-Warning -Message "Error getting Windows Update service information. Error details: $_.Exception.Message"
}
}
function Get-WindowsUpdateStatus {
[CmdletBinding()]
param()
$RebootStatus = @{
'Component Based Servicing' = (Test-Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending')
'PendingFileRenameOperations' = (Test-Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations')
'Windows Update' = (Test-Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired')
}
return $RebootStatus
}
function Get-WindowsUpdateHistory {
[CmdletBinding()]
param(
[Parameter()]
[int]$MaxResults = 100
)
Get-Hotfix | Sort-Object InstalledOn -Descending | Select-Object -First $MaxResults
}
function Get-WindowsUpdateLogs {
[CmdletBinding()]
param()
$updateLogPath = "C:\Windows\Logs\WindowsUpdate\WindowsUpdate.log"
$eventViewerPath = "Microsoft-Windows-WindowsUpdateClient/Operational"
$results = @{
'UpdateLog' = $null
'EventLogs' = $null
}
if (Test-Path $updateLogPath) {
$results.UpdateLog = Get-Content $updateLogPath
}
try {
$results.EventLogs = Get-WinEvent -LogName $eventViewerPath -MaxEvents 100
}
catch {
Write-Warning -Message "Error getting Windows Update event logs. Error details: $_.Exception.Message"
}
return $results
}
Export-ModuleMember -Function @(
'Get-WindowsUpdateServiceInfo',
'Get-WindowsUpdateStatus',
'Get-WindowsUpdateHistory',
'Get-WindowsUpdateLogs'
)