-
Notifications
You must be signed in to change notification settings - Fork 8
/
New-CMClientHealthSummaryReport.ps1
920 lines (845 loc) · 27.7 KB
/
New-CMClientHealthSummaryReport.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
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
<#
.Synopsis
Generates an overview of client health in your Configuration Manager environment as an html email
.DESCRIPTION
This script dynamically builds an html report based on key client health related data from the Configuration Manager database. The script is intended to be run regularly as a scheduled task.
.EXAMPLE
To run as a scheduled task, use a command like the following:
Powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File "<path>\New-CMClientHealthSummaryReport.ps1"
.NOTES
More information can be found here: http://smsagent.wordpress.com/free-configmgr-reports/client-health-summary-report/
The Parameters region should be updated for your environment before executing the script
Author: Trevor Jones @trevor_smsagent
v1.0 - 2016/11/02 - Intial release
#>
#region Parameters
# Database info
$script:dataSource = 'sqlsrv-01\INST_SCCM' # SQL Server name (and instance where applicable)
$script:database = 'CM_ABC' # ConfigMgr Database name
# Email params
$EmailParams = @{
To = 'Joe.Blow@contoso.com'
From = 'POSH_Reporting@contoso.com'
Smtpserver = 'mysmtpserver'
Subject = "ConfigMgr Client Health Summary | $(Get-Date -Format dd-MMM-yyyy)"
}
# Reporting thresholds (percentages)
<#
>= Good - reports as green in the progress bar
>= Warning - reports as amber in the progress bar
< Warning - reports as red in the progress bar
#>
$script:Thresholds = @{}
$Thresholds.Good = 90
$Thresholds.Warning = 80
$Thresholds.Inventory = @{} # Inventory thresholds are applicable to HW inventory, SW inventory and Heartbeat (DDR) only
$Thresholds.Inventory.Good = 85
$Thresholds.Inventory.Warning = 70
#endregion
#region Functions
# Function to run a sql query
function Get-SQLData {
param($Query)
$connectionString = "Server=$dataSource;Database=$database;Integrated Security=SSPI;"
$connection = New-Object -TypeName System.Data.SqlClient.SqlConnection
$connection.ConnectionString = $connectionString
$connection.Open()
$command = $connection.CreateCommand()
$command.CommandText = $Query
$reader = $command.ExecuteReader()
$table = New-Object -TypeName 'System.Data.DataTable'
$table.Load($reader)
# Close the connection
$connection.Close()
return $Table
}
# Function to set the progress bar colour based on the the threshold value
function Set-PercentageColour {
param(
[int]$Value,
[switch]$UseInventoryThresholds
)
If ($UseInventoryThresholds)
{
$Good = $Thresholds.Inventory.Good
$Warning = $Thresholds.Inventory.Warning
}
Else
{
$Good = $Thresholds.Good
$Warning = $Thresholds.Warning
}
If ($Value -ge $Good)
{
$Hex = "#00ff00" # Green
}
If ($Value -ge $Warning -and $Value -lt $Good)
{
$Hex = "#ff9900" # Amber
}
If ($Value -lt $Warning)
{
$Hex = "#FF0000" # Red
}
Return $Hex
}
#endregion
# Create html header
$html = @"
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css">
<body>
"@
# Create has table to store data
$Data = @{}
#region Get Client Count
$Query = "
Select count(ResourceID) as 'Count' from v_R_System where (Client0 = 1)
"
$Data.ClientCount = Get-SQLData -Query $Query | Select -ExpandProperty Count
# Get No Client Count
$Query = "
Select count(ResourceID) as 'Count' from v_R_System where (Client0 = 0 or Client0 is null) and Unknown0 is null
"
$Data.NoClientCount = Get-SQLData -Query $Query | Select -ExpandProperty Count
# Calculate Client Percentage
$Data.ClientCountPercentage = [Math]::Round($Data.ClientCount / ($Data.ClientCount + $Data.NoClientCount) * 100)
$Data.NoClientCountPercentage = 100 - $Data.ClientCountPercentage
$Data.TotalDiscoveredSystems = $Data.ClientCount + $Data.NoClientCount
# Set html
$html = $html + @"
<h2>Discovered Systems with Client Installed</h2>
<table cellpadding="0" cellspacing="0" width="400">
<tr>
<td style="background-color:$(Set-PercentageColour -Value $Data.ClientCountPercentage);padding:10px;color:#ffffff;" width="$($Data.ClientCountPercentage)%">
$($Data.ClientCountPercentage)%
</td>
<td style="background-color:#eeeeee;padding-top:10px;padding-bottom:10px;color:#333333;" width="$($Data.NoClientCountPercentage)%">
</td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" width="400">
<tr>
<td style="padding:5px;" width="80%">
Discovered Systems with Client
</td>
<td style="padding:5px;" width="20%">
$($Data.ClientCount)
</td>
</tr>
<tr>
<td style="padding:5px;" width="80%">
Discovered Systems without Client
</td>
<td style="padding:5px;" width="20%">
$($Data.NoClientCount)
</td>
</tr>
<tr>
<td style="padding:5px;" width="80%">
Total
</td>
<td style="padding:5px;" width="20%">
$($Data.TotalDiscoveredSystems)
</td>
</tr>
</table>
"@
#endregion
#region Get Active Count
$Query = "
Select count(ResourceID) as 'Count' from v_CH_ClientSummary where ClientActiveStatus = 1
"
$Data.ActiveCount = Get-SQLData -Query $Query | Select -ExpandProperty Count
# Get InActive Count
$Query = "
Select count(ResourceID) as 'Count' from v_CH_ClientSummary where ClientActiveStatus = 0
"
$Data.InactiveCount = Get-SQLData -Query $Query | Select -ExpandProperty Count
# Calculate Active Percentage
$Data.ActiveCountPercentage = [Math]::Round($Data.ActiveCount / ($Data.ActiveCount + $Data.InactiveCount) * 100)
$Data.InActiveCountPercentage = 100 - $Data.ActiveCountPercentage
$Data.ActiveInactiveTotal = $Data.ActiveCount + $data.InactiveCount
# Set html
$html = $html + @"
<h2>Active Clients</h2>
<table cellpadding="0" cellspacing="0" width="400">
<tr>
<td style="background-color:$(Set-PercentageColour -Value $Data.ActiveCountPercentage);padding:10px;color:#ffffff;" width="$($Data.ActiveCountPercentage)%">
$($Data.ActiveCountPercentage)%
</td>
<td style="background-color:#eeeeee;padding-top:10px;padding-bottom:10px;color:#333333;" width="$($Data.InactiveCountPercentage)%">
</td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" width="400">
<tr>
<td style="padding:5px;" width="80%">
Active Clients
</td>
<td style="padding:5px;" width="20%">
$($Data.ActiveCount)
</td>
</tr>
<tr>
<td style="padding:5px;" width="80%">
Inactive Clients
</td>
<td style="padding:5px;" width="20%">
$($Data.InActiveCount)
</td>
</tr>
<tr>
<td style="padding:5px;" width="80%">
Total
</td>
<td style="padding:5px;" width="20%">
$($Data.ActiveInactiveTotal)
</td>
</tr>
</table>
"@
#endregion
#region Get Active/Pass Count
$Query = "
Select count(ResourceID) as 'Count' from v_CH_ClientSummary where ClientStateDescription = 'Active/Pass'
"
$Data.ActivePassCount = Get-SQLData -Query $Query | Select -ExpandProperty Count
# Get Active/Fail Count
$Query = "
Select count(ResourceID) as 'Count' from v_CH_ClientSummary where ClientStateDescription = 'Active/Fail'
"
$Data.ActiveFailCount = Get-SQLData -Query $Query | Select -ExpandProperty Count
# Get Active/Unknown Count
$Query = "
Select count(ResourceID) as 'Count' from v_CH_ClientSummary where ClientStateDescription = 'Active/Unknown'
"
$Data.ActiveUnknownCount = Get-SQLData -Query $Query | Select -ExpandProperty Count
# Calculate Active/Pass Percentage
$Data.ActivePassCountPercentage = [Math]::Round($Data.ActivePassCount / ($Data.ActivePassCount + $Data.ActiveFailCount + $Data.ActiveUnknownCount) * 100)
$Data.ActiveNotPassCountPercentage = 100 - $Data.ActivePassCountPercentage
# Set html
$html = $html + @"
<h2>Active Clients Health Evaluation</h2>
<table cellpadding="0" cellspacing="0" width="400">
<tr>
<td style="background-color:$(Set-PercentageColour -Value $Data.ActivePassCountPercentage);padding:10px;color:#ffffff;" width="$($Data.ActivePassCountPercentage)%">
$($Data.ActivePassCountPercentage)%
</td>
<td style="background-color:#eeeeee;padding-top:10px;padding-bottom:10px;color:#333333;" width="$($Data.ActiveNotPassCountPercentage)%">
</td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" width="400">
<tr>
<td style="padding:5px;" width="80%">
Active/Pass
</td>
<td style="padding:5px;" width="20%">
$($Data.ActivePassCount)
</td>
</tr>
<tr>
<td style="padding:5px;" width="80%">
Active/Fail
</td>
<td style="padding:5px;" width="20%">
$($Data.ActiveFailCount)
</td>
</tr>
<tr>
<td style="padding:5px;" width="80%">
Active/Unknown
</td>
<td style="padding:5px;" width="20%">
$($Data.ActiveUnknownCount)
</td>
</tr>
</table>
"@
#endregion
#region Get Active DDR Count
$Query = "
Select count(ResourceID) as 'Count' from v_CH_ClientSummary where IsActiveDDR = 1 and ClientActiveStatus = 1
"
$Data.ActiveDDRCount = Get-SQLData -Query $Query | Select -ExpandProperty Count
# Get InActive DDR Count
$Query = "
Select count(ResourceID) as 'Count' from v_CH_ClientSummary where IsActiveDDR = 0 and ClientActiveStatus = 1
"
$Data.InActiveDDRCount = Get-SQLData -Query $Query | Select -ExpandProperty Count
# Calculate Active DDR Percentage
$Data.ActiveDDRCountPercentage = [Math]::Round($Data.ActiveDDRCount / ($Data.ActiveDDRCount + $Data.InActiveDDRCount) * 100)
$Data.InActiveDDRCountPercentage = 100 - $Data.ActiveDDRCountPercentage
# Set html
$html = $html + @"
<h2>Active Clients Heartbeat (DDR)</h2>
<table cellpadding="0" cellspacing="0" width="400">
<tr>
<td style="background-color:$(Set-PercentageColour -Value $Data.ActiveDDRCountPercentage -UseInventoryThresholds);padding:10px;color:#ffffff;" width="$($Data.ActiveDDRCountPercentage)%">
$($Data.ActiveDDRCountPercentage)%
</td>
<td style="background-color:#eeeeee;padding-top:10px;padding-bottom:10px;color:#333333;" width="$($Data.InActiveDDRCountPercentage)%">
</td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" width="400">
<tr>
<td style="padding:5px;" width="80%">
Active DDR
</td>
<td style="padding:5px;" width="20%">
$($Data.ActiveDDRCount)
</td>
</tr>
<tr>
<td style="padding:5px;" width="80%">
Inactive DDR
</td>
<td style="padding:5px;" width="20%">
$($Data.InActiveDDRCount)
</td>
</tr>
</table>
"@
#endregion
#region Get Active HW Count
$Query = "
Select count(ResourceID) as 'Count' from v_CH_ClientSummary where IsActiveHW = 1 and ClientActiveStatus = 1
"
$Data.ActiveHWCount = Get-SQLData -Query $Query | Select -ExpandProperty Count
# Get InActive HW Count
$Query = "
Select count(ResourceID) as 'Count' from v_CH_ClientSummary where IsActiveHW = 0 and ClientActiveStatus = 1
"
$Data.InActiveHWCount = Get-SQLData -Query $Query | Select -ExpandProperty Count
# Calculate Active HW Percentage
$Data.ActiveHWCountPercentage = [Math]::Round($Data.ActiveHWCount / ($Data.ActiveHWCount + $Data.InActiveHWCount) * 100)
$Data.InActiveHWCountPercentage = 100 - $Data.ActiveHWCountPercentage
# Set html
$html = $html + @"
<h2>Active Clients Hardware Inventory</h2>
<table cellpadding="0" cellspacing="0" width="400">
<tr>
<td style="background-color:$(Set-PercentageColour -Value $Data.ActiveHWCountPercentage -UseInventoryThresholds);padding:10px;color:#ffffff;" width="$($Data.ActiveHWCountPercentage)%">
$($Data.ActiveHWCountPercentage)%
</td>
<td style="background-color:#eeeeee;padding-top:10px;padding-bottom:10px;color:#333333;" width="$($Data.InActiveHWCountPercentage)%">
</td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" width="400">
<tr>
<td style="padding:5px;" width="80%">
Active HW Inventory
</td>
<td style="padding:5px;" width="20%">
$($Data.ActiveHWCount)
</td>
</tr>
<tr>
<td style="padding:5px;" width="80%">
Inactive HW Inventory
</td>
<td style="padding:5px;" width="20%">
$($Data.InActiveHWCount)
</td>
</tr>
</table>
"@
#endregion
#region Get Active SW Count
$Query = "
Select count(ResourceID) as 'Count' from v_CH_ClientSummary where IsActiveSW = 1 and ClientActiveStatus = 1
"
$Data.ActiveSWCount = Get-SQLData -Query $Query | Select -ExpandProperty Count
# Get InActive SW Count
$Query = "
Select count(ResourceID) as 'Count' from v_CH_ClientSummary where IsActiveSW = 0 and ClientActiveStatus = 1
"
$Data.InActiveSWCount = Get-SQLData -Query $Query | Select -ExpandProperty Count
# Calculate Active SW Percentage
$Data.ActiveSWCountPercentage = [Math]::Round($Data.ActiveSWCount / ($Data.ActiveSWCount + $Data.InActiveSWCount) * 100)
$Data.InActiveSWCountPercentage = 100 - $Data.ActiveSWCountPercentage
# Set html
$html = $html + @"
<h2>Active Clients Software Inventory</h2>
<table cellpadding="0" cellspacing="0" width="400">
<tr>
<td style="background-color:$(Set-PercentageColour -Value $Data.ActiveSWCountPercentage -UseInventoryThresholds);padding:10px;color:#ffffff;" width="$($Data.ActiveSWCountPercentage)%">
$($Data.ActiveSWCountPercentage)%
</td>
<td style="background-color:#eeeeee;padding-top:10px;padding-bottom:10px;color:#333333;" width="$($Data.InActiveSWCountPercentage)%">
</td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" width="400">
<tr>
<td style="padding:5px;" width="80%">
Active SW Inventory
</td>
<td style="padding:5px;" width="20%">
$($Data.ActiveSWCount)
</td>
</tr>
<tr>
<td style="padding:5px;" width="80%">
Inactive SW Inventory
</td>
<td style="padding:5px;" width="20%">
$($Data.InActiveSWCount)
</td>
</tr>
</table>
"@
#endregion
#region Get Active PolicyRequest Count
$Query = "
Select count(ResourceID) as 'Count' from v_CH_ClientSummary where IsActivePolicyRequest = 1 and ClientActiveStatus = 1
"
$Data.ActivePRCount = Get-SQLData -Query $Query | Select -ExpandProperty Count
# Get InActive PolicyRequest Count
$Query = "
Select count(ResourceID) as 'Count' from v_CH_ClientSummary where IsActivePolicyRequest = 0 and ClientActiveStatus = 1
"
$Data.InActivePRCount = Get-SQLData -Query $Query | Select -ExpandProperty Count
# Calculate Active PolicyRequest Percentage
$Data.ActivePRCountPercentage = [Math]::Round($Data.ActivePRCount / ($Data.ActivePRCount + $Data.InActivePRCount) * 100)
$Data.InActivePRCountPercentage = 100 - $Data.ActivePRCountPercentage
# Set html
$html = $html + @"
<h2>Active Clients Policy Request</h2>
<table cellpadding="0" cellspacing="0" width="400">
<tr>
<td style="background-color:$(Set-PercentageColour -Value $Data.ActivePRCountPercentage);padding:10px;color:#ffffff;" width="$($Data.ActivePRCountPercentage)%">
$($Data.ActivePRCountPercentage)%
</td>
<td style="background-color:#eeeeee;padding-top:10px;padding-bottom:10px;color:#333333;" width="$($Data.InActivePRCountPercentage)%">
</td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" width="400">
<tr>
<td style="padding:5px;" width="80%">
Active Policy Request
</td>
<td style="padding:5px;" width="20%">
$($Data.ActivePRCount)
</td>
</tr>
<tr>
<td style="padding:5px;" width="80%">
Inactive Policy Request
</td>
<td style="padding:5px;" width="20%">
$($Data.InActivePRCount)
</td>
</tr>
</table>
"@
#endregion
#region Get Client Versions
$Query = "
Select sys.Client_Version0 as 'Client Version', count (sys.ResourceID) as 'Count' from v_R_System sys
inner join v_CH_ClientSummary ch on sys.ResourceID = ch.ResourceID
where ch.ClientActiveStatus = 1
Group by sys.Client_Version0
Order by sys.Client_Version0 desc
"
$Data.ClientVersions = Get-SQLData -Query $Query
$Data.TotalForClientVersions = [int]0
$data.ClientVersions | foreach {
$Data.TotalForClientVersions = $Data.TotalForClientVersions + $_.Count
}
# Set html
$html = $html + @"
<br><br>
<h2>Client Versions</h2>
<table cellpadding="0" cellspacing="0" width="400">
<tr>
<th style="text-align: left" width="240">Version</th>
<th style="text-align: left" width="80">Count</th>
<th style="text-align: left" width="80">Percent</th>
</tr>
</table>
"@
$Data.ClientVersions | foreach {
$Percentage = [Math]::Round($_.Count / $Data.TotalForClientVersions * 100)
$PercentageRemaining = (100 - $Percentage)
$html = $html + @"
<table cellpadding="0" cellspacing="0" width="400">
<tr>
<td style="padding:5px;" width="240">
$($_.'Client Version')
</td>
<td style="padding:5px;" width="80">
$($_.Count)
</td>
<td style="padding:5px;" width="80">
$($Percentage)%
</td>
</tr>
</table>
"@
}
#endregion
#region Get No Client Systems
$Data.NoClient = @{}
# no client - unknown OS
$Query = "
Select count(ResourceID) as 'Count' from v_R_System
where (Client0 = 0 or Client0 is null)
and Unknown0 is null
and Operating_System_Name_and0 like 'unknown%'
"
$Data.NoClient.UnknownOS = Get-SQLData -Query $Query | Select -ExpandProperty Count
# no client windows OS
$Query = "
Select count(ResourceID) as 'Count' from v_R_System
where (Client0 = 0 or Client0 is null)
and Unknown0 is null
and Operating_System_Name_and0 like '%Windows%'
"
$Data.NoClient.WindowsOS = Get-SQLData -Query $Query | Select -ExpandProperty Count
# no client other OS
$Query = "
Select count(ResourceID) as 'Count' from v_R_System
where (Client0 = 0 or Client0 is null)
and Unknown0 is null
and Operating_System_Name_and0 not like '%Windows%'
and Operating_System_Name_and0 not like 'unknown%'
"
$Data.NoClient.OtherOS = Get-SQLData -Query $Query | Select -ExpandProperty Count
# no client and no last logon timestamp in last 7 days
$Query = "
Select count(ResourceID) as 'Count' from v_R_System
where (Client0 = 0 or Client0 is null)
and Unknown0 is null
and (DATEDIFF(day,Last_Logon_Timestamp0, GetDate())) >= 7
"
$Data.NoClient.GTLast7 = Get-SQLData -Query $Query | Select -ExpandProperty Count
# no client and last logon timestamp within last 7 days
$Query = "
Select count(ResourceID) as 'Count' from v_R_System
where (Client0 = 0 or Client0 is null)
and Unknown0 is null
and (DATEDIFF(day,Last_Logon_Timestamp0, GetDate())) < 7
"
$Data.NoClient.LTLast7 = Get-SQLData -Query $Query | Select -ExpandProperty Count
# Set html
$html = $html + @"
<br><br>
<h2>Systems with No Client</h2>
<table cellpadding="0" cellspacing="0" width="400">
<tr>
<th style="text-align: left" width="240">Category</th>
<th style="text-align: left" width="80">Count</th>
<th style="text-align: left" width="80">Percent</th>
</tr>
</table>
"@
$html = $html + @"
<table cellpadding="0" cellspacing="0" width="400">
<tr>
<td style="padding:5px;" width="240">
Windows OS
</td>
<td style="padding:5px;" width="80">
$($Data.NoClient.WindowsOS)
</td>
<td style="padding:5px;" width="80">
$([Math]::Round($Data.NoClient.WindowsOS / $Data.NoClientCount * 100))%
</td>
</tr>
<tr>
<td style="padding:5px;" width="240">
Other OS
</td>
<td style="padding:5px;" width="80">
$($Data.NoClient.OtherOS)
</td>
<td style="padding:5px;" width="80">
$([Math]::Round($Data.NoClient.OtherOS / $Data.NoClientCount * 100))%
</td>
</tr>
<tr>
<td style="padding:5px;" width="240">
Unknown OS
</td>
<td style="padding:5px;" width="80">
$($Data.NoClient.UnknownOS)
</td>
<td style="padding:5px;" width="80">
$([Math]::Round($Data.NoClient.UnknownOS / $Data.NoClientCount * 100))%
</td>
</tr>
<tr>
<td style="padding:5px;" width="240">
Last Logon > 7 days
</td>
<td style="padding:5px;" width="80">
$($Data.NoClient.GTLast7)
</td>
<td style="padding:5px;" width="80">
$([Math]::Round($Data.NoClient.GTLast7 / $Data.NoClientCount * 100))%
</td>
</tr>
<tr>
<td style="padding:5px;" width="240">
Last Logon < 7 days
</td>
<td style="padding:5px;" width="80">
$($Data.NoClient.LTLast7)
</td>
<td style="padding:5px;" width="80">
$([Math]::Round($Data.NoClient.LTLast7 / $Data.NoClientCount * 100))%
</td>
</tr>
</table>
"@
#endregion
#region Windows Client Installation Failures
$Query = "
select count(cdr.MachineID) as 'Count',
cdr.CP_LastInstallationError as 'Error Code'
from v_CombinedDeviceResources cdr
where
cdr.IsClient = 0
and cdr.DeviceOS like '%Windows%'
group by cdr.CP_LastInstallationError
"
$InstallErrors = Get-SQLData -Query $Query
# Translate error codes to friendly names and add the percentage value
$TotalErrors = 0
$InstallErrors | foreach {
$TotalErrors = $TotalErrors + $_.Count
}
$Data.InstallFailures = $InstallErrors | Select Count,'Error Code',@{n='Error Description';e={([ComponentModel.Win32Exception]$_.'Error Code').Message}},@{n='Percentage';e={[Math]::Round($_.Count / $TotalErrors * 100)}} | Sort Count -Descending
# Set html
$html = $html + @"
<br><br>
<h2>Windows Client Installation Failures</h2>
<table cellpadding="0" cellspacing="0" width="600">
<tr>
<th style="text-align: left" width="100">Error Code</th>
<th style="text-align: left" width="300">Error Description</th>
<th style="text-align: left" width="100">Count</th>
<th style="text-align: left" width="100">Percent</th>
</tr>
</table>
"@
$Data.InstallFailures | foreach {
$html = $html + @"
<table cellpadding="0" cellspacing="0" width="600">
<tr>
<td style="padding:5px;" width="100">
$($_.'Error Code')
</td>
<td style="padding:5px;" width="300">
$($_.'Error Description')
</td>
<td style="padding:5px;" width="100">
$($_.Count)
</td>
<td style="padding:5px;" width="100">
$($_.Percentage)%
</td>
</tr>
</table>
"@
}
#endregion
#region Computer reboots
# Active systems with a known Last BootUp Time
$Query = "
select Count(ch.ResourceID) as 'Count'
from v_CH_ClientSummary ch
left join v_GS_OPERATING_SYSTEM os on os.ResourceId = ch.ResourceId
where os.LastBootUpTime0 is not null
and ch.ClientActiveStatus = 1
"
$Data.ActiveLastBootUpTotal = Get-SQLData -Query $Query | Select -ExpandProperty Count
# Computer reboot dates
$Query = "
select '7 days' as TimePeriod,Count(sys.Name0) as 'Count',1 SortOrder
from v_R_System sys
inner join v_GS_OPERATING_SYSTEM os on os.ResourceId = sys.ResourceId
inner join v_CH_ClientSummary ch on ch.ResourceID = sys.ResourceID
where os.LastBootUpTime0 < DATEADD(day,-7, GETDATE())
and ch.ClientActiveStatus = 1
UNION
select '14 days' as TimePeriod,Count(sys.Name0) as 'Count',2
from v_R_System sys
inner join v_GS_OPERATING_SYSTEM os on os.ResourceId = sys.ResourceId
inner join v_CH_ClientSummary ch on ch.ResourceID = sys.ResourceID
where os.LastBootUpTime0 < DATEADD(day,-14, GETDATE())
and ch.ClientActiveStatus = 1
UNION
select '1 month' as TimePeriod,Count(sys.Name0) as 'Count',3
from v_R_System sys
inner join v_GS_OPERATING_SYSTEM os on os.ResourceId = sys.ResourceId
inner join v_CH_ClientSummary ch on ch.ResourceID = sys.ResourceID
where os.LastBootUpTime0 < DATEADD(month,-1, GETDATE())
and ch.ClientActiveStatus = 1
UNION
select '3 months' as TimePeriod,Count(sys.Name0) as 'Count',4
from v_R_System sys
inner join v_GS_OPERATING_SYSTEM os on os.ResourceId = sys.ResourceId
inner join v_CH_ClientSummary ch on ch.ResourceID = sys.ResourceID
where os.LastBootUpTime0 < DATEADD(MONTH,-3, GETDATE())
and ch.ClientActiveStatus = 1
UNION
select '6 months' as TimePeriod,Count(sys.Name0) as 'Count',5
from v_R_System sys
inner join v_GS_OPERATING_SYSTEM os on os.ResourceId = sys.ResourceId
inner join v_CH_ClientSummary ch on ch.ResourceID = sys.ResourceID
where os.LastBootUpTime0 < DATEADD(MONTH,-6, GETDATE())
and ch.ClientActiveStatus = 1
Order By SortOrder
"
$Data.ComputerReboots = Get-SQLData -Query $Query
# Set html
$html = $html + @"
<br><br>
<h2>Computers Not Rebooted</h2>
<table cellpadding="0" cellspacing="0" width="400">
<tr>
<th style="text-align: left" width="240">Time Period</th>
<th style="text-align: left" width="80">Count</th>
<th style="text-align: left" width="80">Percent*</th>
</tr>
</table>
"@
$html = $html + @"
<table cellpadding="0" cellspacing="0" width="400">
<tr>
<td style="padding:5px;" width="240">
$($Data.ComputerReboots[0].TimePeriod)
</td>
<td style="padding:5px;" width="80">
$($Data.ComputerReboots[0].Count)
</td>
<td style="padding:5px;" width="80">
$([Math]::Round($Data.ComputerReboots[0].Count / $Data.ActiveLastBootUpTotal * 100))%
</td>
</tr>
<tr>
<td style="padding:5px;" width="240">
$($Data.ComputerReboots[1].TimePeriod)
</td>
<td style="padding:5px;" width="80">
$($Data.ComputerReboots[1].Count)
</td>
<td style="padding:5px;" width="80">
$([Math]::Round($Data.ComputerReboots[1].Count / $Data.ActiveLastBootUpTotal * 100))%
</td>
</tr>
<tr>
<td style="padding:5px;" width="240">
$($Data.ComputerReboots[2].TimePeriod)
</td>
<td style="padding:5px;" width="80">
$($Data.ComputerReboots[2].Count)
</td>
<td style="padding:5px;" width="80">
$([Math]::Round($Data.ComputerReboots[2].Count / $Data.ActiveLastBootUpTotal * 100))%
</td>
</tr>
<tr>
<td style="padding:5px;" width="240">
$($Data.ComputerReboots[3].TimePeriod)
</td>
<td style="padding:5px;" width="80">
$($Data.ComputerReboots[3].Count)
</td>
<td style="padding:5px;" width="80">
$([Math]::Round($Data.ComputerReboots[3].Count / $Data.ActiveLastBootUpTotal * 100))%
</td>
</tr>
<tr>
<td style="padding:5px;" width="240">
$($Data.ComputerReboots[4].TimePeriod)
</td>
<td style="padding:5px;" width="80">
$($Data.ComputerReboots[4].Count)
</td>
<td style="padding:5px;" width="80">
$([Math]::Round($Data.ComputerReboots[4].Count / $Data.ActiveLastBootUpTotal * 100))%
</td>
</tr>
</table>
<div style="font-size: 12px">* Percentage is calculated from the total number of active clients that have a known last bootup time ($($Data.ActiveLastBootUpTotal))</div>
"@
#endregion
#region Client Health Thresholds
$Query = "
SELECT *
FROM v_CH_Settings
where SettingsID = 1
"
$Data.CHSettings = Get-SQLData -Query $Query
# Set html
$html = $html + @"
<br><br>
<h2>Client Status Settings</h2>
<table cellpadding="0" cellspacing="0" width="400">
<tr>
<th style="text-align: left" width="300">Setting</th>
<th style="text-align: left" width="100">Days</th>
</tr>
</table>
"@
$html = $html + @"
<table cellpadding="0" cellspacing="0" width="400">
<tr>
<td style="padding:5px;" width="300">
Heartbeat Discovery
</td>
<td style="padding:5px;" width="100">
$($data.CHSettings.DDRInactiveInterval)
</td>
</tr>
<tr>
<td style="padding:5px;" width="300">
Hardware Inventory
</td>
<td style="padding:5px;" width="100">
$($data.CHSettings.HWInactiveInterval)
</td>
</tr>
<tr>
<td style="padding:5px;" width="300">
Software Inventory
</td>
<td style="padding:5px;" width="100">
$($data.CHSettings.SWInactiveInterval)
</td>
</tr>
<tr>
<td style="padding:5px;" width="300">
Policy Requests
</td>
<td style="padding:5px;" width="100">
$($data.CHSettings.PolicyInactiveInterval)
</td>
</tr>
<tr>
<td style="padding:5px;" width="300">
Status History Retention
</td>
<td style="padding:5px;" width="100">
$($data.CHSettings.CleanUpInterval)
</td>
</tr>
</table>
"@
#endregion
# Close html document
$html = $html + @"
</body>
</html>
"@
# Send email
Send-MailMessage @EmailParams -Body $html -BodyAsHtml