-
Notifications
You must be signed in to change notification settings - Fork 0
/
VMM2012Update-Baselines.ps1
158 lines (118 loc) · 7.03 KB
/
VMM2012Update-Baselines.ps1
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<#
.Synopsis
Script to automatically keep SCVMM Baselines in sync with WSUS
.DESCRIPTION
Script that synchronizes WSUS Updates with SCVMM, both adding new updates and removes old inactive updates.
.EXAMPLE
Update-BaseLineUpdates $Baselinename
# Author
Current Author, Markus Lassfolk @Truesec
Original Author, Mikael Nyström @Truesec
# Version 1.5
Markus Lassfolk
- Minor tewaks and changes
# Version 1.2
Markus Lassfolk
- Added section to remove inactive updates
# Version 1.0
Markus Lassfolk
- Initial Release
# Version 0.5
Mikael Nyström
#>
Function Update-BaseLineUpdates{
Param (
[Parameter(Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false,
Position=0)]
[String]
$BaseLineName
)
$baseline = Get-SCBaseline -Name $BaseLineName
# Set-SCBaseline -Baseline $baseline -Name $BaseLineName -Description $BaseLineName -RemoveUpdates $baseline.Updates
write-host $baseline.UpdateCount : Current number of Updates in Baseline $BaseLineName
$addedUpdateList = "$null"
$addedUpdateList = @()
if ($baseline.UpdateCount -eq 0) {
if ($baseline -notlike "Drivers") {
write-host "No previous updates in" $BaselineName", adding all existing updates for" $BaseLineName "from WSUS"
$addedUpdateList += Get-SCUpdate | Where-Object -Property UpdateClassification -EQ -Value $BaseLineName | Where-Object -Property IsApproved -Like -Value "True" | Where-Object -Property IsDeclined -Like -Value "False"| Where-Object -Property IsExpired -Like -Value "False" | Where-Object -Property IsSuperseded -Like -Value "False"
write-host $addedUpdateList.Count ": New updates to add in" $Baseline
Set-SCBaseline -Baseline $baseline -Name $BaseLineName -Description $BaseLineName -AddUpdates $addedUpdateList
}
if ($Baseline -like "Drivers") {
write-host "No previous updates in" $BaselineName", adding all existing updates for" $BaseLineName "from WSUS"
$addedUpdateList += Get-SCUpdate | Where-Object -Property UpdateClassification -EQ -Value Drivers | Where-Object -Property IsApproved -Like -Value "True" | Where-Object -Property IsDeclined -Like -Value "False"| Where-Object -Property IsExpired -Like -Value "False" | Where-Object -Property IsSuperseded -Like -Value "False" | Where-Object Products -Like "*Windows Server*"
write-host $addedUpdateList.Count ": New updates to add in" $Baseline
Set-SCBaseline -Baseline $baseline -Name $BaseLineName -Description $BaseLineName -AddUpdates $addedUpdateList
}
}
if ($baseline.UpdateCount -gt 0 ) {
if ($baseline -notlike "Drivers") {
write-host "Scanning WSUS Updates for matching updates for $BaselineName"
$LatestUpdates = Get-SCUpdate | Where-Object -Property UpdateClassification -EQ -Value $BaseLineName | Where-Object -Property IsApproved -Like -Value "True" | Where-Object -Property IsDeclined -Like -Value "False"| Where-Object -Property IsExpired -Like -Value "False" | Where-Object -Property IsSuperseded -Like -Value "False"
write-host $LatestUpdates.Count ": Updates found, verifying if update(s) already exist in" $BaseLineName
Compare-Object -ReferenceObject $baseline.Updates -DifferenceObject $LatestUpdates -IncludeEqual | % {
if($_.SideIndicator -eq '=>') { $addedUpdateList += Get-SCUpdate -ID $_.inputobject.id }
}
}
if ($Baseline -like "Drivers") {
write-host "Scanning WSUS Updates for matching updates for $BaselineName"
$LatestUpdates = Get-SCUpdate | Where-Object -Property UpdateClassification -EQ -Value $BaseLineName | Where-Object -Property IsApproved -Like -Value "True" | Where-Object -Property IsDeclined -Like -Value "False"| Where-Object -Property IsExpired -Like -Value "False" | Where-Object -Property IsSuperseded -Like -Value "False" | Where-Object Products -Like "*Windows Server*"
write-host $LatestUpdates.Count ": Updates found, verifying if update(s) already exist in" $BaseLineName
Compare-Object -ReferenceObject $baseline.Updates -DifferenceObject $LatestUpdates -IncludeEqual | % {
if($_.SideIndicator -eq '=>') { $addedUpdateList += Get-SCUpdate -ID $_.inputobject.id }
}
}
}
write-host $addedUpdateList.Count : New updates to be added to SCVMM for $BaseLineName
# write-host $addedUpdateList | ft
Set-SCBaseline -Baseline $baseline -Name $BaseLineName -Description $BaseLineName -AddUpdate $addedUpdateList
write-host "Scan WSUS for Updates that should not be Checked anymore"
$remove = ""
$remove = @()
$removeUpdateList = ""
$removeUpdateList = @()
$remove += Get-SCUpdate | Where-Object -Property UpdateClassification -EQ -Value $BaseLineName | Where-Object -Property IsApproved -Like -Value "False"
$remove += Get-SCUpdate | Where-Object -Property UpdateClassification -EQ -Value $BaseLineName | Where-Object -Property IsDeclined -Like -Value "True"
$remove += Get-SCUpdate | Where-Object -Property UpdateClassification -EQ -Value $BaseLineName | Where-Object -Property IsExpired -Like -Value "True"
$remove += Get-SCUpdate | Where-Object -Property UpdateClassification -EQ -Value $BaseLineName | Where-Object -Property IsSuperseded -Like -Value "True"
write-host $remove.count "Remove Unapproved/Superseded/Expired/Declined updates"
Compare-Object -ReferenceObject $baseline.Updates -DifferenceObject $remove -IncludeEqual | % {
if($_.SideIndicator -eq '==') { $removeUpdateList += Get-SCUpdate -ID $_.inputobject.id }
}
Set-SCBaseline -Baseline $baseline -Name $BaseLineName -Description $BaseLineName -RemoveUpdates $RemoveupdateList
}
Function Add-BaseLine{
Param (
[Parameter(Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false,
Position=0)]
[String]
$BaseLineName
)
$baseline = New-SCBaseline -Name $BaseLineName -Description $BaseLineName
$scope = Get-SCVMHostGroup -Name "All Hosts"
Set-SCBaseline -Baseline $baseline -AddAssignmentScope $scope
$scope2 = Get-SCVMMManagedComputer
ForEach($Server in $scope2){
Set-SCBaseline -Baseline $baseline -Name $baseLine -AddAssignmentScope $Server
}
}
Write-Host "Synchronizing with WSUS Server"
Get-SCUpdateServer | Start-SCUpdateServerSynchronization
. Update-BaseLineUpdates "Security Updates"
. Update-BaseLineUpdates "Critical Updates"
. Update-BaseLineUpdates "Updates"
. Update-BaseLineUpdates "Update Rollups"
. Update-BaseLineUpdates "Hotfix"
. Update-BaseLineUpdates "Drivers"
#. Update-BaseLineUpdates "Definition Updates"
. Update-BaseLineUpdates "Service Packs"
. Update-BaseLineUpdates "Feature Packs"
write-host "Start Compliance Scan for all Servers"
Get-SCVMMManagedComputer | Start-SCComplianceScan -RunAsynchronously