-
Notifications
You must be signed in to change notification settings - Fork 3
/
wsus-report-2.ps1
636 lines (569 loc) · 45.9 KB
/
wsus-report-2.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
<#
WSUS Report
** Requires WSUS Administrator Console Installed or UpdateServices Module available **
TO DO:
- SUSDB Size
- Computers in Active Directory but not in WSUS (OPTIONAL)
#>
#region User Specified WSUS Information
$WSUSServer = 'WSUS-SERVER'
#Accepted values are "80","443","8530" and "8531"
$Port = 8530
$UseSSL = $False
#Specify when a computer is considered stale
$DaysComputerStale = 30
#Send email of report
[bool]$SendEmail = $TRUE
#Display HTML file
[bool]$ShowFile = $FALSE
#endregion User Specified WSUS Information
#region User Specified Email Information
$EmailParams = @{
From = 'WSUSReport@YOUR-DOMAIN'
Subject = "$WSUSServer WSUS Report"
SMTPServer = 'SMTP-SERVER'
BodyAsHtml = $True
}
#endregion User Specified Email Information
#region Helper Functions
Function Set-AlternatingCSSClass {
[CmdletBinding()]
param(
[Parameter(Mandatory=$True,ValueFromPipeline=$True)]
[string]$HTMLFragment,
[Parameter(Mandatory=$True)]
[string]$CSSEvenClass,
[Parameter(Mandatory=$True)]
[string]$CssOddClass
)
[xml]$xml = $HTMLFragment
$table = $xml.SelectSingleNode('table')
$classname = $CSSOddClass
foreach ($tr in $table.tr) {
if ($classname -eq $CSSEvenClass) {
$classname = $CssOddClass
} else {
$classname = $CSSEvenClass
}
$class = $xml.CreateAttribute('class')
$class.value = $classname
$tr.attributes.append($class) | Out-null
}
$xml.innerxml | out-string
}
Function Convert-Size {
<#
.SYSNOPSIS
Converts a size in bytes to its upper most value.
.DESCRIPTION
Converts a size in bytes to its upper most value.
.PARAMETER Size
The size in bytes to convert
.NOTES
Author: Boe Prox
Date Created: 22AUG2012
.EXAMPLE
Convert-Size -Size 568956
555 KB
Description
-----------
Converts the byte value 568956 to upper most value of 555 KB
.EXAMPLE
Get-ChildItem | ? {! $_.PSIsContainer} | Select -First 5 | Select Name, @{L='Size';E={$_ | Convert-Size}}
Name Size
---- ----
Data1.cap 14.4 MB
Data2.cap 12.5 MB
Image.iso 5.72 GB
Index.txt 23.9 KB
SomeSite.lnk 1.52 KB
SomeFile.ini 152 bytes
Description
-----------
Used with Get-ChildItem and custom formatting with Select-Object to list the uppermost size.
#>
[cmdletbinding()]
Param (
[parameter(ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
[Alias("Length")]
[int64]$Size
)
Begin {
If (-Not $ConvertSize) {
Write-Verbose ("Creating signature from Win32API")
$Signature = @"
[DllImport("Shlwapi.dll", CharSet = CharSet.Auto)]
public static extern long StrFormatByteSize( long fileSize, System.Text.StringBuilder buffer, int bufferSize );
"@
$Global:ConvertSize = Add-Type -Name SizeConverter -MemberDefinition $Signature -PassThru
}
Write-Verbose ("Building buffer for string")
$stringBuilder = New-Object Text.StringBuilder 1024
}
Process {
Write-Verbose ("Converting {0} to upper most size" -f $Size)
$ConvertSize::StrFormatByteSize( $Size, $stringBuilder, $stringBuilder.Capacity ) | Out-Null
$stringBuilder.ToString()
}
}
#endregion Helper Functions
#region Load WSUS Required Assembly
If (-Not (Get-Module -ListAvailable -Name UpdateServices)) {
#Add-Type "$Env:ProgramFiles\Update Services\Api\Microsoft.UpdateServices.Administration.dll"
$Null = [reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")
} Else {
Import-Module -Name UpdateServices
}
#endregion Load WSUS Required Assembly
#region CSS Layout
$head=@"
<style>
h1 {
text-align:center;
border-bottom:1px solid #666666;
color:#009933;
}
TABLE {
TABLE-LAYOUT: fixed;
FONT-SIZE: 90%;
WIDTH: 100%
}
* {
margin:0
}
.pageholder {
margin: 0px auto;
}
td {
VERTICAL-ALIGN: TOP;
FONT-FAMILY: Tahoma
}
th {
VERTICAL-ALIGN: TOP;
COLOR: #018AC0;
TEXT-ALIGN: left;
background-color:DarkGrey;
color:Black;
}
body {
text-align:left;
font-smoothing:always;
width:100%;
}
.odd { background-color:#ffffff; }
.even { background-color:#dddddd; }
</style>
"@
#endregion CSS Layout
#region Initial WSUS Connection
$ErrorActionPreference = 'Stop'
Try {
$Wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer($WSUSServer,$UseSSL,$Port)
} Catch {
Write-warning "$($WSUSServer)<$($Port)>: $($_)"
Break
}
$ErrorActionPreference = 'Continue'
#endregion Initial WSUS Connection
#region Pre-Stage -- Used in more than one location
$htmlFragment = ''
$WSUSConfig = $Wsus.GetConfiguration()
$WSUSStats = $Wsus.GetStatus()
$TargetGroups = $Wsus.GetComputerTargetGroups()
$EmptyTargetGroups = $TargetGroups | Where {
$_.GetComputerTargets().Count -eq 0 -AND $_.Name -ne 'Unassigned Computers'
}
#Stale Computers
$computerscope = New-Object Microsoft.UpdateServices.Administration.ComputerTargetScope
$computerscope.ToLastReportedStatusTime = (Get-Date).AddDays(-$DaysComputerStale)
$StaleComputers = $wsus.GetComputerTargets($computerscope) | ForEach {
[pscustomobject]@{
Computername = $_.FullDomainName
ID= $_.Id
IPAddress = $_.IPAddress
LastReported = $_.LastReportedStatusTime
LastSync = $_.LastSyncTime
TargetGroups = ($_.GetComputerTargetGroups() | Select -Expand Name) -join ', '
}
}
#Pending Reboots
$updateScope = New-Object Microsoft.UpdateServices.Administration.UpdateScope
$updateScope.IncludedInstallationStates = 'InstalledPendingReboot'
$computerScope = New-Object Microsoft.UpdateServices.Administration.ComputerTargetScope
$computerScope.IncludedInstallationStates = 'InstalledPendingReboot'
$GroupRebootHash=@{}
$ComputerPendingReboot = $wsus.GetComputerTargets($computerScope) | ForEach {
$Update = ($_.GetUpdateInstallationInfoPerUpdate($updateScope) | ForEach {
$Update = $_.GetUpdate()
$Update.title
}) -join ', '
If ($Update) {
$TempTargetGroups = ($_.GetComputerTargetGroups() | Select -Expand Name)
$TempTargetGroups | ForEach {
$GroupRebootHash[$_]++
}
[pscustomobject] @{
Computername = $_.FullDomainName
ID = $_.Id
IPAddress = $_.IPAddress
TargetGroups = $TempTargetGroups -join ', '
#Updates = $Update
}
}
} | Sort Computername
#Failed Installations
$updateScope = New-Object Microsoft.UpdateServices.Administration.UpdateScope
$updateScope.IncludedInstallationStates = 'Failed'
$computerScope = New-Object Microsoft.UpdateServices.Administration.ComputerTargetScope
$computerScope.IncludedInstallationStates = 'Failed'
$GroupFailHash=@{}
$ComputerHash = @{}
$UpdateHash = @{}
$ComputerFailInstall = $wsus.GetComputerTargets($computerScope) | ForEach {
$Computername = $_.FullDomainName
$Update = ($_.GetUpdateInstallationInfoPerUpdate($updateScope) | ForEach {
$Update = $_.GetUpdate()
$Update.title
$ComputerHash[$Computername] += ,$Update.title
$UpdateHash[$Update.title] += ,$Computername
}) -join ', '
If ($Update) {
$TempTargetGroups = ($_.GetComputerTargetGroups() | Select -Expand Name)
$TempTargetGroups | ForEach {
$GroupFailHash[$_]++
}
[pscustomobject] @{
Computername = $_.FullDomainName
ID = $_.Id
IPAddress = $_.IPAddress
TargetGroups = $TempTargetGroups -join ', '
Updates = $Update
}
}
} | Sort Computername
#endregion Pre-Stage -- Used in more than one location
#region WSUS SERVER INFORMATION
$Pre = @"
<div style='margin: 0px auto; BACKGROUND-COLOR:Blue;Color:White;font-weight:bold;FONT-SIZE: 16pt;'>
WSUS Server Information
</div>
"@
#region WSUS Version
$WSUSVersion = [pscustomobject]@{
Computername = $WSUS.ServerName
Version = $Wsus.Version
Port = $Wsus.PortNumber
ServerProtocolVersion = $Wsus.ServerProtocolVersion
}
$Pre += @"
<div style='margin: 0px auto; BACKGROUND-COLOR:LightBlue;Color:Black;font-weight:bold;FONT-SIZE: 14pt;'>
WSUS Information
</div>
"@
$Body = $WSUSVersion | ConvertTo-Html -Fragment | Out-String | Set-AlternatingCSSClass -CSSEvenClass 'even' -CssOddClass 'odd'
$Post = "<br>"
$htmlFragment += $Pre,$Body,$Post
#endregion WSUS Version
#region WSUS Server Content
$drive = $WSUSConfig.LocalContentCachePath.Substring(0,2)
$Data = Get-CIMInstance -ComputerName $WSUSServer -ClassName Win32_LogicalDisk -Filter "DeviceID='$drive'"
$UsedSpace = $data.Size - $data.Freespace
$PercentFree = "{0:P}" -f ($Data.Freespace / $Data.Size)
$Pre = @"
<div style='margin: 0px auto; BACKGROUND-COLOR:LightBlue;Color:Black;font-weight:bold;FONT-SIZE: 14pt;'>
WSUS Server Content Drive
</div>
"@
$WSUSDrive = [pscustomobject]@{
LocalContentPath = $WSUSConfig.LocalContentCachePath
TotalSpace = $data.Size | Convert-Size
UsedSpace = $UsedSpace | Convert-Size
FreeSpace = $Data.freespace | Convert-Size
PercentFree = $PercentFree
}
$Body = $WSUSDrive | ConvertTo-Html -Fragment | Out-String | Set-AlternatingCSSClass -CSSEvenClass 'even' -CssOddClass 'odd'
$Post = "<br>"
$htmlFragment += $Pre,$Body,$Post
#endregion WSUS Server Content
#region Last Synchronization
$synch = $wsus.GetSubscription()
$SynchHistory = $Synch.GetSynchronizationHistory()[0]
$WSUSSynch = [pscustomobject]@{
IsAuto = $synch.SynchronizeAutomatically
SynchTime = $synch.SynchronizeAutomaticallyTimeOfDay
LastSynch = $synch.LastSynchronizationTime
Result = $SynchHistory.Result
}
If ($SynchHistory.Result -eq 'Failed') {
$WSUSSynch = $WSUSSynch | Add-Member -MemberType NoteProperty -Name ErrorType -Value $SynchHistory.Error -PassThru |
Add-Member -MemberType NoteProperty -Name ErrorText -Value $SynchHistory.ErrorText -PassThru
}
$Pre = @"
<div style='margin: 0px auto; BACKGROUND-COLOR:LightBlue;Color:Black;font-weight:bold;FONT-SIZE: 14pt;'>
Last Server Synchronization
</div>
"@
$Body = $WSUSSynch | ConvertTo-Html -Fragment | Out-String | Set-AlternatingCSSClass -CSSEvenClass 'even' -CssOddClass 'odd'
$Post = "<br>"
$htmlFragment += $Pre,$Body,$Post
#endregion Last Synchronization
#region Upstream Server Config
$WSUSUpdateConfig = [pscustomobject]@{
SyncFromMU = $WSUSConfig.SyncFromMicrosoftUpdate
UpstreamServer = $WSUSConfig.UpstreamWsusServerName
UpstreamServerPort = $WSUSConfig.UpstreamWsusServerPortNumber
SSLConnection = $WSUSConfig.UpstreamWsusServerUseSsl
}
$Pre = @"
<div style='margin: 0px auto; BACKGROUND-COLOR:LightBlue;Color:Black;font-weight:bold;FONT-SIZE: 14pt;'>
Upstream Server Information
</div>
"@
$Body = $WSUSUpdateConfig | ConvertTo-Html -Fragment | Out-String | Set-AlternatingCSSClass -CSSEvenClass 'even' -CssOddClass 'odd'
$Post = "<br>"
$htmlFragment += $Pre,$Body,$Post
#endregion Upstream Server Config
#region Automatic Approvals
$Rules = $wsus.GetInstallApprovalRules()
$ApprovalRules = $Rules | ForEach {
[pscustomobject]@{
Name= $_.Name
ID = $_.ID
Enabled = $_.Enabled
Action = $_.Action
Categories = ($_.GetCategories() | Select -ExpandProperty Title) -join ', '
Classifications = ($_.GetUpdateClassifications() | Select -ExpandProperty Title) -join ', '
TargetGroups = ($_.GetComputerTargetGroups() | Select -ExpandProperty Name) -join ', '
}
}
$Pre = @"
<div style='margin: 0px auto; BACKGROUND-COLOR:LightBlue;Color:Black;font-weight:bold;FONT-SIZE: 14pt;'>
Automatic Approvals
</div>
"@
$Body = $ApprovalRules | ConvertTo-Html -Fragment | Out-String | Set-AlternatingCSSClass -CSSEvenClass 'even' -CssOddClass 'odd'
$Post = "<br>"
$htmlFragment += $Pre,$Body,$Post
#endregion Automatic Approvals
#region WSUS Child Servers
$ChildUpdateServers = $wsus.GetChildServers()
If ($ChildUpdateServers) {
$ChildServers = $ChildUpdateServers | ForEach {
[pscustomobject]@{
ChildServer = $_.FullDomainName
Version = $_.Version
UpstreamServer = $_.UpdateServer.Name
LastSyncTime = $_.LastSyncTime
SyncsFromDownStreamServer = $_.SyncsFromDownStreamServer
LastRollUpTime = $_.LastRollupTime
IsReplica = $_.IsReplica
}
}
}
$Pre = @"
<div style='margin: 0px auto; BACKGROUND-COLOR:LightBlue;Color:Black;font-weight:bold;FONT-SIZE: 14pt;'>
Child Servers
</div>
"@
$Body = $ChildServers | ConvertTo-Html -Fragment | Out-String | Set-AlternatingCSSClass -CSSEvenClass 'even' -CssOddClass 'odd'
$Post = "<br>"
$htmlFragment += $Pre,$Body,$Post
#endregion WSUS Child Servers
#region Database Information
$WSUSDB = $WSUS.GetDatabaseConfiguration()
$DBInfo = [pscustomobject]@{
DatabaseName = $WSUSDB.databasename
Server = $WSUSDB.ServerName
IsDatabaseInternal = $WSUSDB.IsUsingWindowsInternalDatabase
Authentication = $WSUSDB.authenticationmode
}
$Pre = @"
<div style='margin: 0px auto; BACKGROUND-COLOR:LightBlue;Color:Black;font-weight:bold;FONT-SIZE: 14pt;'>
WSUS Database
</div>
"@
$Body = $DBInfo | ConvertTo-Html -Fragment | Out-String | Set-AlternatingCSSClass -CSSEvenClass 'even' -CssOddClass 'odd'
$Post = "<br>"
$htmlFragment += $Pre,$Body,$Post
#endregion Database Information
#endregion WSUS SERVER INFORMATION
#region CLIENT INFORMATION
$Pre = @"
<div style='margin: 0px auto; BACKGROUND-COLOR:Blue;Color:White;font-weight:bold;FONT-SIZE: 16pt;'>
WSUS Client Information
</div>
"@
#region Computer Statistics
$WSUSComputerStats = [pscustomobject]@{
TotalComputers = [int]$WSUSStats.ComputerTargetCount
"Stale($DaysComputerStale Days)" = ($StaleComputers | Measure-Object).count
NeedingUpdates = [int]$WSUSStats.ComputerTargetsNeedingUpdatesCount
FailedInstall = [int]$WSUSStats.ComputerTargetsWithUpdateErrorsCount
PendingReboot = ($ComputerPendingReboot | Measure-Object).Count
}
$Pre += @"
<div style='margin: 0px auto; BACKGROUND-COLOR:LightBlue;Color:Black;font-weight:bold;FONT-SIZE: 14pt;'>
Computer Statistics
</div>
"@
$Body = $WSUSComputerStats | ConvertTo-Html -Fragment | Out-String | Set-AlternatingCSSClass -CSSEvenClass 'even' -CssOddClass 'odd'
$Post = "<br>"
$htmlFragment += $Pre,$Body,$Post
#endregion Computer Statistics
#region Operating System
$Pre = @"
<div style='margin: 0px auto; BACKGROUND-COLOR:LightBlue;Color:Black;font-weight:bold;FONT-SIZE: 14pt;'>
By Operating System
</div>
"@
$Body = $wsus.GetComputerTargets() | Group OSDescription |
Select @{L='OperatingSystem';E={$_.Name}}, Count |
ConvertTo-Html -Fragment | Out-String | Set-AlternatingCSSClass -CSSEvenClass 'even' -CssOddClass 'Odd'
$Post = "<br>"
$htmlFragment += $Pre,$Body,$Post
#endregion Operating System
#region Stale Computers
$Pre = @"
<div style='margin: 0px auto; BACKGROUND-COLOR:LightBlue;Color:Black;font-weight:bold;FONT-SIZE: 14pt;'>
Stale Computers ($DaysComputerStale Days)
</div>
"@
$Body = $StaleComputers | ConvertTo-Html -Fragment | Out-String | Set-AlternatingCSSClass -CSSEvenClass 'even' -CssOddClass 'odd'
$Post = "<br>"
$htmlFragment += $Pre,$Body,$Post
#endregion Stale Computers
#region Unassigned Computers
$Unassigned = ($TargetGroups | Where {
$_.Name -eq 'Unassigned Computers'
}).GetComputerTargets() | ForEach {
[pscustomobject]@{
Computername = $_.FullDomainName
OperatingSystem = $_.OSDescription
ID= $_.Id
IPAddress = $_.IPAddress
LastReported = $_.LastReportedStatusTime
LastSync = $_.LastSyncTime
}
}
$Pre = @"
<div style='margin: 0px auto; BACKGROUND-COLOR:LightBlue;Color:Black;font-weight:bold;FONT-SIZE: 14pt;'>
Unassigned Computers (in Unassigned Target Group)
</div>
"@
$Body = $Unassigned | ConvertTo-Html -Fragment | Out-String | Set-AlternatingCSSClass -CSSEvenClass 'even' -CssOddClass 'odd'
$Post = "<br>"
$htmlFragment += $Pre,$Body,$Post
#endregion Unassigned Computers
#region Failed Update Install
$Pre = @"
<div style='margin: 0px auto; BACKGROUND-COLOR:LightBlue;Color:Black;font-weight:bold;FONT-SIZE: 14pt;'>
Failed Update Installations By Computer
</div>
"@
$Body = $ComputerFailInstall | ConvertTo-Html -Fragment | Out-String | Set-AlternatingCSSClass -CSSEvenClass 'even' -CssOddClass 'odd'
$Post = "<br>"
$htmlFragment += $Pre,$Body,$Post
#endregion Failed Update Install
#region Pending Reboot
$Pre = @"
<div style='margin: 0px auto; BACKGROUND-COLOR:LightBlue;Color:Black;font-weight:bold;FONT-SIZE: 14pt;'>
Computers with Pending Reboot
</div>
"@
$Body = $ComputerPendingReboot | ConvertTo-Html -Fragment | Out-String | Set-AlternatingCSSClass -CSSEvenClass 'even' -CssOddClass 'odd'
$Post = "<br>"
$htmlFragment += $Pre,$Body,$Post
#endregion Pending Reboot
#endregion CLIENT INFORMATION
#region UPDATE INFORMATION
$Pre = @"
<div style='margin: 0px auto; BACKGROUND-COLOR:Blue;Color:White;font-weight:bold;FONT-SIZE: 16pt;'>
WSUS Update Information
</div>
"@
#region Update Statistics
$WSUSUpdateStats = [pscustomobject]@{
TotalUpdates = [int]$WSUSStats.UpdateCount
Needed = [int]$WSUSStats.UpdatesNeededByComputersCount
Approved = [int]$WSUSStats.ApprovedUpdateCount
Declined = [int]$WSUSStats.DeclinedUpdateCount
ClientInstallError = [int]$WSUSStats.UpdatesWithClientErrorsCount
UpdatesNeedingFiles = [int]$WSUSStats.ExpiredUpdateCount
}
$Pre += @"
<div style='margin: 0px auto; BACKGROUND-COLOR:LightBlue;Color:Black;font-weight:bold;FONT-SIZE: 14pt;'>
Update Statistics
</div>
"@
$Body = $WSUSUpdateStats | ConvertTo-Html -Fragment | Out-String | Set-AlternatingCSSClass -CSSEvenClass 'even' -CssOddClass 'odd'
$Post = "<br>"
$htmlFragment += $Pre,$Body,$Post
#endregion Update Statistics
#region Failed Update Installations
$FailedUpdateInstall = $UpdateHash.GetEnumerator() | ForEach {
[pscustomobject]@{
Update = $_.Name
Computername = ($_.Value) -join ', '
}
}
$Pre = @"
<div style='margin: 0px auto; BACKGROUND-COLOR:LightBlue;Color:Black;font-weight:bold;FONT-SIZE: 14pt;'>
Failed Update Installations By Update
</div>
"@
$Body = $FailedUpdateInstall | ConvertTo-Html -Fragment | Out-String | Set-AlternatingCSSClass -CSSEvenClass 'even' -CssOddClass 'odd'
$Post = "<br>"
$htmlFragment += $Pre,$Body,$Post
#endregion Failed Update Installations
#endregion UPDATE INFORMATION
#region TARGET GROUP INFORMATION
$Pre = @"
<div style='margin: 0px auto; BACKGROUND-COLOR:Blue;Color:White;font-weight:bold;FONT-SIZE: 16pt;'>
WSUS Target Group Information
</div>
"@
#region Target Group Statistics
$GroupStats = [pscustomobject]@{
TotalGroups = [int]$TargetGroups.count
TotalEmptyGroups = [int]$EmptyTargetGroups.Count
}
$Pre += @"
<div style='margin: 0px auto; BACKGROUND-COLOR:LightBlue;Color:Black;font-weight:bold;FONT-SIZE: 14pt;'>
Target Group Statistics
</div>
"@
$Body = $GroupStats | ConvertTo-Html -Fragment | Out-String | Set-AlternatingCSSClass -CSSEvenClass 'even' -CssOddClass 'odd'
$Post = "<br>"
$htmlFragment += $Pre,$Body,$Post
#endregion Target Group Statistics
#region Empty Groups
$Pre = @"
<div style='margin: 0px auto; BACKGROUND-COLOR:LightBlue;Color:Black;font-weight:bold;FONT-SIZE: 14pt;'>
Empty Target Groups
</div>
"@
$Body = $EmptyTargetGroups | Select Name, ID | ConvertTo-Html -Fragment | Out-String | Set-AlternatingCSSClass -CSSEvenClass 'even' -CssOddClass 'odd'
$Post = "<br>"
$htmlFragment += $Pre,$Body,$Post
#endregion Empty Groups
#endregion TARGET GROUP INFORMATION
#region Compile HTML Report
$HTMLParams = @{
Head = $Head
Title = "WSUS Report for $WSUSServer"
PreContent = "<H1><font color='white'>Please view in html!</font><br>$WSUSServer WSUS Report</H1>"
PostContent = "$($htmlFragment)<i>Report generated on $((Get-Date).ToString())</i>"
}
$Report = ConvertTo-Html @HTMLParams | Out-String
#endregion Compile HTML Report
If ($ShowFile) {
$Report | Out-File WSUSReport.html
Invoke-Item WSUSReport.html
}
#region Send Email
If ($SendEmail) {
$EmailParams.Body = $Report
Send-MailMessage @EmailParams
}
#endregion Send Email