/
Microsoft.Windows.Active.Directory.Certificate.Services.2016.Monitoring.Addendum.xml
3036 lines (2794 loc) · 176 KB
/
Microsoft.Windows.Active.Directory.Certificate.Services.2016.Monitoring.Addendum.xml
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
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?><ManagementPack ContentReadable="true" SchemaVersion="2.0" OriginalSchemaVersion="1.1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<Manifest>
<Identity>
<ID>Microsoft.Windows.Active.Directory.Certificate.Services.2016.Monitoring.Addendum</ID>
<Version>1.0.1.0</Version>
</Identity>
<Name>Microsoft Windows Active Directory Certificate Services 2016 Monitoring Addendum</Name>
<References>
<Reference Alias="Health">
<ID>System.Health.Library</ID>
<Version>6.1.7221.0</Version>
<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
</Reference>
<Reference Alias="MSIGL">
<ID>Microsoft.SystemCenter.InstanceGroup.Library</ID>
<Version>6.1.7221.0</Version>
<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
</Reference>
<Reference Alias="MWA6M">
<ID>Microsoft.Windows.ActiveDirectoryCertificateServices.2016.Monitoring</ID>
<Version>10.0.0.0</Version>
<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
</Reference>
<Reference Alias="MWA6D">
<ID>Microsoft.Windows.ActiveDirectoryCertificateServices.2016.Discovery</ID>
<Version>10.0.0.0</Version>
<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
</Reference>
<Reference Alias="MWIIS6">
<ID>Microsoft.Windows.InternetInformationServices.2016</ID>
<Version>10.0.0.0</Version>
<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
</Reference>
<Reference Alias="MWS6D">
<ID>Microsoft.Windows.Server.2016.Discovery</ID>
<Version>6.0.7323.0</Version>
<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
</Reference>
<Reference Alias="MWSAD6D">
<ID>Microsoft.Windows.Server.AD.2016.Discovery</ID>
<Version>10.0.0.0</Version>
<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
</Reference>
<Reference Alias="MWSAD6M">
<ID>Microsoft.Windows.Server.AD.2016.Monitoring</ID>
<Version>10.0.0.0</Version>
<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
</Reference>
<Reference Alias="SC">
<ID>Microsoft.SystemCenter.Library</ID>
<Version>6.1.7221.0</Version>
<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
</Reference>
<Reference Alias="SCCUC">
<ID>SystemCenterCentral.Utilities.Certificates</ID>
<Version>1.4.3.0</Version>
<PublicKeyToken>e5c80663d573f08c</PublicKeyToken>
</Reference>
<Reference Alias="System">
<ID>System.Library</ID>
<Version>7.5.8501.0</Version>
<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
</Reference>
<Reference Alias="Windows">
<ID>Microsoft.Windows.Library</ID>
<Version>6.1.7221.0</Version>
<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
</Reference>
</References>
</Manifest>
<TypeDefinitions>
<EntityTypes>
<ClassTypes>
<ClassType ID="Microsoft.Windows.Active.Directory.Certificate.Services.2016.OCSP.Seed.Class" Accessibility="Public" Abstract="false" Base="Windows!Microsoft.Windows.LocalApplication" Hosted="true" Singleton="false" Extension="false" />
<ClassType ID="Microsoft.Windows.Active.Directory.Certificate.Services.2016.OnlineResponderService.Seed.Class" Accessibility="Public" Abstract="false" Base="Windows!Microsoft.Windows.LocalApplication" Hosted="true" Singleton="false" Extension="false" />
<ClassType ID="Microsoft.Windows.Active.Directory.Certificate.Services.2016.OnlineResponderService.Customizations.Group" Accessibility="Public" Abstract="false" Base="MSIGL!Microsoft.SystemCenter.InstanceGroup" Hosted="false" Singleton="true" Extension="false" />
</ClassTypes>
</EntityTypes>
<ModuleTypes>
<DataSourceModuleType ID="Microsoft.Windows.Active.Directory.Certificate.Services.2016.OnlineResponderService.Customizations.EventID7031.Monitor.DataSource" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element minOccurs="1" type="xsd:integer" name="IntervalSeconds" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
<xsd:element minOccurs="0" type="xsd:string" name="SyncTime" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
<xsd:element minOccurs="1" type="xsd:integer" name="TimeoutSeconds" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int" />
<OverrideableParameter ID="SyncTime" Selector="$Config/SyncTime$" ParameterType="string" />
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int" />
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="Scheduler" TypeID="System!System.Scheduler">
<Scheduler>
<SimpleReccuringSchedule>
<Interval Unit="Seconds">$Config/IntervalSeconds$</Interval>
<SyncTime>$Config/SyncTime$</SyncTime>
</SimpleReccuringSchedule>
<ExcludeDates />
</Scheduler>
</DataSource>
<ProbeAction ID="PA" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe">
<ScriptName>Microsoft.Windows.Active.Directory.Certificate.Services.2016.OnlineResponderService.EventID7031.Monitor.DS.v1010.ps1</ScriptName>
<ScriptBody>
#=================================================================================
# Check for 7031 events for Microsoft Windows Active Directory Certificate Services 2016 OnlineResponderService EventID7031 events
#
# Author: Kevin Justin
# v1.0
#=================================================================================
# Constants section - modify stuff here:
#=================================================================================
# Assign script name variable for use in event logging.
$ScriptName = "Microsoft.Windows.Active.Directory.Certificate.Services.2016.OnlineResponderService.EventID7031.Monitor.DS.v1010.ps1"
$EventID = "661"
#=================================================================================
# Starting Script section - All scripts get this
#=================================================================================
# Gather the start time of the script
$StartTime = Get-Date
#Set variable to be used in logging events
$whoami = whoami
# Load MOMScript API
$momapi = New-Object -comObject MOM.ScriptAPI
# Load PropertyBag function
$bag = $momapi.CreatePropertyBag()
#Log script event that we are starting task
$momapi.LogScriptEvent($ScriptName,$EventID,0,"Script is starting. `n Running as ($whoami).")
#=================================================================================
# Begin MAIN script section
#=================================================================================
$ServiceName = "OCSPSvc"
$ADCSServices = @()
$ADCSServices += "OCSPSvc"
$ADCSServices
#
#For a simple example - get files in Windows Temp:
$date = get-date -uFormat "%Y-%m-%d"
$momapi.LogScriptEvent($ScriptName,$EventID,0,"Gather Microsoft Windows Active Directory Certificate Services 2016 System Event ID 7031 Alerts for date ($date).")
# Grab past 15 minutes
$Time = [DateTime](Get-Date).AddMinutes(-15)
$SystemEvents = get-eventlog -LogName "System" -after $Time `
| ? { ( $_.EventID -eq 7031 )`
}
$7031Events = foreach ( $Service in $ADCSServices )
{
$SystemEvents | ? { ($_.Message -like "*$Service*") }
}
# Create array for services messages
$ADCSServiceMessage = @()
# Check if service is running
if ( $7031Events.Count -eq 0 )
{
write-host "ZERO Microsoft Windows Active Directory Certificate Services 2016 7031 events found in past 15 minutes"
}
if ( $7031Events.Count -gt 0 )
{
foreach ( $Service in $ADCSServices )
{
if ( $(get-service $Service).Status -ne "running" )
{
get-service $Service; start-service $Service ; sleep 15
#Set the condition = bad. This represents your script finding something wrong
$strCondition = "Bad"
$ADCSServiceMessage += "Microsoft Windows Active Directory Certificate Services 2016 OCSPSvc service $Service NOT running after automated service restart"
$momapi.LogScriptEvent($ScriptName,$EventID,0,"Microsoft Windows Active Directory Certificate Services 2016 service $Service NOT running after automated service restart")
#$momapi.LogScriptEvent($ScriptName,$EventID,0,"$7031ActiveRolesMessage")
$bag.AddValue('Result','BadCondition')
#$bag.AddValue('Result',$strCondition)
$bag.AddValue('Count',$SystemEvents.count)
$bag.AddValue('Summary',$7031ActiveRolesMessage)
}
}
}
$ADCSServiceMessage
# Gather report data
$7031ActiveRolesMessage = @()
if ( $SystemEvents.count -eq 0 )
{
$7031ActiveRolesMessage += ""
$7031ActiveRolesMessage += "ZERO Microsoft Windows Active Directory Certificate Services 2016 7031 events found ($date)."
$7031ActiveRolesMessage += ""
$strCondition = "Good"
$momapi.LogScriptEvent($ScriptName,$EventID,0,"NO Microsoft Windows Active Directory Certificate Services 2016 7031 events found in past 15 minutes")
$bag.AddValue('Result','GoodCondition')
#$bag.AddValue('Result',$strCondition)
$bag.AddValue('Count',$SystemEvents.count)
$bag.AddValue('Summary',$7031ActiveRolesMessage)
}
if ( $SystemEvents.count -gt 0 )
{
$7031ActiveRolesMessage += ""
$7031ActiveRolesMessage += "#"
$7031ActiveRolesMessage += "# Number of 7031 Events with Quest OneIdentity AR ActiveRoles service failures"
$7031ActiveRolesMessage += $SystemEvents.Count
$7031ActiveRolesMessage += ""
$7031ActiveRolesMessage += "# Details"
$7031ActiveRolesMessage += "#========================================================"
$7031ActiveRolesMessage += $7031Events | select TimeGenerated,Message
$7031ActiveRolesMessage += "#========================================================"
$7031ActiveRolesMessage += ""
if ( $ADCSServiceMessage.Count -gt 0 )
{
$7031ActiveRolesMessage += "# Quest OneIdentity AR ActiveRoles service restart details"
$7031ActiveRolesMessage += "#========================================================"
$7031ActiveRolesMessage += $ADCSServiceMessage
$7031ActiveRolesMessage += "#========================================================"
$7031ActiveRolesMessage += ""
}
}
$7031ActiveRolesMessage
$7031ActiveRolesMessage = $7031ActiveRolesMessage | out-string
# Log messages to event
$momapi.LogScriptEvent($ScriptName,$EventID,0,"$7031ActiveRolesMessage")
# Return all bags
$bag
# End of script section
#=================================================================================
#Log an event for script ending and total execution time.
$EndTime = Get-Date
$ScriptTime = ($EndTime - $StartTime).TotalSeconds
$momapi.LogScriptEvent($ScriptName,$EventID,0,"Script Completed. `n Script Runtime: ($ScriptTime) seconds.")
#=================================================================================
# End of script
</ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="PA">
<Node ID="Scheduler" />
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
</DataSourceModuleType>
<DataSourceModuleType ID="Proactive.DailyTasks.ADCSAlerts.Close.Script.DataSource" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element minOccurs="1" type="xsd:integer" name="TimeoutSeconds" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int" />
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="Scheduler" TypeID="System!System.Scheduler">
<Scheduler>
<WeeklySchedule>
<Windows>
<Daily>
<Start>06:17</Start>
<End>06:37</End>
<DaysOfWeekMask>62</DaysOfWeekMask>
</Daily>
</Windows>
</WeeklySchedule>
<ExcludeDates />
</Scheduler>
</DataSource>
<ProbeAction ID="PA" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe">
<ScriptName>Proactive.DailyTasks.ADCSAlerts.Close.Script.Datasource.v1010.ps1</ScriptName>
<ScriptBody>
#=================================================================================
# Script to gather ADCS alerts and close via on demand task
#
# Author: Kevin Justin
# v1.0
#=================================================================================
# Constants section - modify stuff here:
#=================================================================================
# Assign script name variable for use in event logging.
# ScriptName should be the same as the ID of the module that the script is contained in
$ScriptName = "Proactive.DailyTasks.ADCSAlerts.Close.Script.Datasource.v1010.ps1"
$EventID = "550"
#=================================================================================
# Starting Script section - All scripts get this
#=================================================================================
# Gather the start time of the script
$StartTime = Get-Date
#Set variable to be used in logging events
$whoami = whoami
# Load MOMScript API
$momapi = New-Object -comObject MOM.ScriptAPI
#Log script event that we are starting task
$momapi.LogScriptEvent($ScriptName,$EventID,0,"Script is starting. `n Running as ($whoami).")
#=================================================================================
# PropertyBag Script section - Monitoring scripts get this
#=================================================================================
# Load SCOM PropertyBag function
$bag = $momapi.CreatePropertyBag()
#=================================================================================
# Begin MAIN script section
#=================================================================================
#For a simple example - get files in Windows Temp:
$date = get-date -uFormat "%Y-%m-%d"
$Age = [DateTime](Get-Date).AddDays(-1)
# Grab past 24 hours
if ( (get-date).DayOfWeek -ne "Monday" )
{
$Time = [DateTime](Get-Date).AddDays(-1)
}
if ( (get-date).DayOfWeek -eq "Monday" )
{
$Time = [DateTime](Get-Date).AddDays(-3)
}
$momapi.LogScriptEvent($ScriptName,$EventID,0,"Gather Proactive DailyTasks ADCS Monitors close automation for ($date).")
$Message = "Proactive DailyTasks ADCS Monitors close automation for ($date)."
# Gather AD alerts
## Grab the MP, get the Monitors and Rules from the MP, then grab all alerts found inside the Monitors/Rules
$SCOMCoreMP = Get-SCOMManagementPack -DisplayName "Windows Server 2016+ Active Directory Certificate Services Monitoring"
$SCOMCoreRules = $SCOMCoreMP.GetRules()
$SCOMCoreMonitors = $SCOMCoreMP.GetMonitors()
$SCOMCoreReportAlerts = Get-SCOMAlert -ResolutionState (0..254) | ? { ($_.Name -in $SCOMCoreRules.DisplayName) -or ($_.Name -in $SCOMCoreMonitors.DisplayName) }
$SCOMCoreReportAlerts.Count
$SCOMCoreRuleAlerts = $SCOMCoreReportAlerts | ? { ( $_.Name -in $SCOMCoreRules.DisplayName) }
$SCOMCoreRuleAlerts.Count
$SCOMCoreMonitorAlerts = $SCOMCoreReportAlerts | ? { ($_.Name -in $SCOMCoreMonitors.DisplayName ) }
$SCOMCoreMonitorAlerts.Count
$SCOMCoreReportAlerts = $SCOMCoreReportAlerts | ? { ($_.Name -in $SCOMCoreRules.DisplayName) -or ($_.Name -in $SCOMCoreMonitors.DisplayName) }
$SCOMCoreReportAlerts.Count
$Test = $SCOMCoreReportAlerts.Count
$OpenADCS2012Alerts = $SCOMCoreReportAlerts
$OpenADCS2012Alerts.Count
$ClosedADCS2012Alerts = get-SCOMAlert -ResolutionState 255 | ? { ($_.Name -in $SCOMCoreRules.DisplayName) -or ($_.Name -in $SCOMCoreMonitors.DisplayName) }
$ClosedADCS2012Alerts.Count
$ADCSAlerts = $SCOMCoreReportAlerts | select MonitoringObjectDisplayName,Description
if ( $Test -eq 0 )
{
$Message = "ZERO ADCS 2016+ alerts to close for ($date)"
$momapi.LogScriptEvent($ScriptName,$EventID,0,"ZERO ADCS 2016+ alerts to close for ($date).")
}
if ( $Test -gt 0 )
{
#
# Build report
$ADCSComponentMessage = @()
$ADCSComponentMessage += ""
$ADCSComponentMessage += $Message
$ADCSComponentMessage += ""
$ADCSComponentMessage += "# ADCS Monitors auto-closed"
$ADCSComponentMessage += "#============================================================"
$ADCSComponentMessage += "# Total ADCS alerts = $($SCOMCoreReportAlerts.Count)"
$ADCSComponentMessage += "#"
$ADCSComponentMessage += "# Open alerts = $($OpenADCSAlerts.Count)"
$ADCSComponentMessage += "# Closed alerts = $($ClosedADCSAlerts.Count)"
$ADCSComponentMessage += "#"
$ADCSComponentMessage += "# Automation closed alerts = $($OpenADCSAlerts.Count)"
$ADCSComponentMessage += "#========================================="
$ADCSComponentMessage += ""
}
$ADCSComponentMessage
$ADCSComponentMessage = $ADCSComponentMessage | out-string
# Log data event before resetting monitors
#============================================================
$Result = "GOOD"
$Message = "Proactive DailyTasks ADCS Monitors close automation for ($date)"
$momapi.LogScriptEvent($ScriptName,$EventID,0,"Proactive DailyTasks ADCS Monitors close automation for ($date). `n `n$ADCSComponentMessage")
#$bag.AddValue('Result',$Result)
$bag.AddValue('Count',$Test)
$bag.AddValue('Message',$Message)
$bag.AddValue('Summary',$ADCSComponentMessage)
# Return all bags
$bag
#=================================================================================
# Reset Monitors Script base code modified
# Put ps1 in mgmtpacks folder
# https://sc.scomurr.com/scom-2012-monitor-reset-cleaning-up-the-environment/
# Download
# https://gallery.technet.microsoft.com/SCOM-2012-Batch-reset-63a17534
#Alternate
#https://gallery.technet.microsoft.com/scriptcenter/Auto-reset-script-for-d8b775ca
# Changed up logic to sort unique classes in mgmnt pack families.
# Added Age variable for monitors thanks to Aris Somatis - $Age specified in top level variables
# Cycling through monitors made reset loop huge ~650 monitors when only ~50 classes
# New logic reduced runtime from 8 minutes to roughly 8 seconds
#=================================================================================
# Write event for rule closure
$momapi.LogScriptEvent($ScriptName,$EventID,0,"Proactive DailyTasks ADCS Monitors reset started for ($date). `n `n $($ADCSMonitorsToAutoClose.Count) ")
if ( $SCOMCoreReportAlerts.Count -gt 0 )
{
# Get ADCS classes
$ADCSLibrary = Get-SCOMManagementPack -name "Microsoft.Windows.CertificateServices.Library"
#get-scomclass -ManagementPack $ADLibrary
$ADCSMonitoring = $SCOMCoreMP
#get-scomclass -ManagementPack $SCOMCoreMP | fl DisplayName,Name,ID
$ADCSDiscovery = Get-SCOMManagementPack -name Microsoft.Windows.ActiveDirectoryCertificateServices.2016.Discovery
#get-scomclass -ManagementPack $ADDiscovery | fl DisplayName,Name,ID
# ADCS pack naming
$ADCSClasses = @(Get-SCOMClass -ManagementPack $ADLibrary; Get-SCOMClass -ManagementPack $ADDiscovery; )
$ADCSClass = $ADCSClasses | sort -property Name -uniq
# Debug
$ADCSClass.Count
# Set up monitor objects to reset
foreach ($Class in $ADCSClass)
{
$ActiveMonitors = @(Get-SCOMClassInstance -Class $Class | ? { ($_.healthstate -ne 'Success') -AND ( $_.healthstate -ne 'Uninitialized') -AND ($_.IsAvailable -eq $true) } )
# Debug
$ActiveMonitors.Count
# $ActiveMonitors | fl -property *
write-host "Found" $ActiveMonitors.Count "unhealthy monitors for class" $Class
foreach ( $UnhealthyOLDMonitor in $ActiveMonitors )
{
#if ( $UnhealthyOLDMonitor.AvailabilityLastModified -lt $Age )
if ( $UnhealthyOLDMonitor.StateLastModified -lt $Age )
{
#$UnhealthyMonitors += $ActiveMonitors.Count
#UnhealthyOLDMonitor | select AvailabilityLastModified,Path,DisplayName
#$UnhealthyOLDMonitor.Count
#write-host "Found" + $UnhealthyOLDMonitor.Count + "unhealthy monitor beyond" $Age "days."
#write-host ""
if ( $ActiveMonitors.Count -gt 0)
{
foreach ( $ActiveMonitor in $UnhealthyOLDMonitor )
{
# Debug
$ActiveMonitor.ID
write-host " Resetting Health State on '" + $ActiveMonitor.FullName + "'"
write-host ""
$ActiveMonitor.ResetMonitoringState($ActiveMonitor)
}
}
}
}
}
# Debug
#$MonitorClass | fl -property *
#$MonitorClass | select DisplayName,ID
}
# Debug Write event for rule closure
# $UnhealthyMonitors = $($UnhealthyMonitors | measure-object -sum).sum
#$momapi.LogScriptEvent($ScriptName,$EventID,0,"Proactive ADCS monitors auto-closed on ($date). `n `n $($ADCSMonitorsToAutoClose.Count) ")
# Write event for rule closure
$momapi.LogScriptEvent($ScriptName,$EventID,0,"Proactive DailyTasks ADCS monitor reset completed for ($date)")
# Unhealthy rules
#
# (Rules) Alerts to auto close after reset monitor
# $SCOMCoreRuleAlerts | Resolve-SCOMAlert
if ( $SCOMCoreReportAlerts.Count -gt 0 )
{
# Debug
#$SCOMCoreRules.DisplayName
$SCOMCoreRules | Resolve-SCOMAlert -Comment "Closing daily alert flood after report alert generated - ADCS Addendum automation DS"
$ADRulesToClose = @()
$ADRulesToClose +=
$ADRulesToClose += "A dll cannot be loaded because the software was incorrectly installed"
$ADRulesToClose += "A DNS server used by this server for name resolution*"
$ADRulesToClose += "A resource record for the computer name of the DC*"
$ADRulesToClose += "A RSoP (Resultant Set of Policies) error occurred"
$ADRulesToClose += "A user from a different forest*"
$ADRulesToClose += "A well known *"
$ADRulesToClose += "Account creation will *"
$ADRulesToClose += "Account Name Not Unique"
$ADRulesToClose += "Accounts with the same SID*"
$ADRulesToClose += "Active Directory Web Services *"
$ADRulesToClose += "ADCS*"
$ADRulesToClose += "AD Database Size Collection"
$ADRulesToClose += "AD Replication Queue"
$ADRulesToClose += "An account *"
$ADRulesToClose += "An attempt to *"
$ADRulesToClose += "Change Password on KRBTGT Account Failed"
$ADRulesToClose += "Corrupt Credentials"
$ADRulesToClose += "Domain Operation Mode has been changed to Native Mode"
$ADRulesToClose += "Duplicate account names were detected - one account has been renamed"
$ADRulesToClose += "Duplicate User Principal Names have been detected"
$ADRulesToClose += "Free Disk Space * Collection"
$ADRulesToClose += "Global Catalog Search Response Time Collection"
$ADRulesToClose += "Group policy processing aborted - cannot determine site"
$ADRulesToClose += "Invalid Forwarded AS Request"
$ADRulesToClose += "Invalid Policy Data"
$ADRulesToClose += "Machine account policy failure - *"
$ADRulesToClose += "Memory Allocation Error - the system may be overloaded"
$ADRulesToClose += "No input provider to sync time"
$ADRulesToClose += "One or more of the DC Locator DNS records are not registered in the DNS*"
$ADRulesToClose += "PAC Verification Failure"
$ADRulesToClose += "Policy Update Failure"
$ADRulesToClose += "Setting the administrators password failed. It has been reset to blank."
$ADRulesToClose += "The account identifier pool for this domain controller cannot be updated"
$ADRulesToClose += "The computer did not have sufficient rights to perform the secure dynami*"
$ADRulesToClose += "The computer name cannot be mapped to an object in Active Directory - *"
$ADRulesToClose += "The DC was unable to obtain the next account-identifier"
$ADRulesToClose += "The DNS server with which this DC will register does not support the *"
$ADRulesToClose += "The domain controller failed to obtain a new account identifier pool"
$ADRulesToClose += "The group caching option has now been properly updated"
$ADRulesToClose += "The machine account cannot be found"
$ADRulesToClose += "The number of Group Policies has exceeded the maximum limit"
$ADRulesToClose += "The registry policy file could not be accessed during application *"
$ADRulesToClose += "The system clock has not been synchronized for some time"
$ADRulesToClose += "This domain controller will not start up because its machine account*"
$ADRulesToClose += "Trusted Domain List Update Failure"
$ADRulesToClose += "Unexpected SAM Failure"
$ADRulesToClose += "Windows cannot determine the *"
$ADRulesToClose += "Windows cannot obtain the domain controller name for your computer network."
$ADRulesToClose += "Windows is setting a registry value"
foreach ( $alert in $ADRulesToClose )
{
get-scomalert -name $alert | Resolve-SCOMAlert -Comment "ADCS addendum alert rule automation completed"
}
# End of rule automation cleanup
}
# Write event for rule closure
$momapi.LogScriptEvent($ScriptName,$EventID,0,"Proactive DailyTasks ADCS rule reset completed for ($date)")
#=================================================================================
# End MAIN script section
# End of script section
#=================================================================================
#Log an event for script ending and total execution time.
$EndTime = Get-Date
$ScriptTime = ($EndTime - $StartTime).TotalSeconds
$momapi.LogScriptEvent($ScriptName,$EventID,0,"Script Completed. `n Script Runtime: ($ScriptTime) seconds.")
#=================================================================================
# End of script
</ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="PA">
<Node ID="Scheduler" />
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
</DataSourceModuleType>
<DataSourceModuleType ID="Proactive.DailyTasks.ADCSAlerts.SummaryReport.Script.DataSource" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element minOccurs="1" type="xsd:integer" name="TimeoutSeconds" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int" />
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="Scheduler" TypeID="System!System.Scheduler">
<Scheduler>
<WeeklySchedule>
<Windows>
<Daily>
<Start>05:31</Start>
<End>06:01</End>
<DaysOfWeekMask>62</DaysOfWeekMask>
</Daily>
</Windows>
</WeeklySchedule>
<ExcludeDates />
</Scheduler>
</DataSource>
<ProbeAction ID="PA" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe">
<ScriptName>Proactive.DailyTasks.ADCSAlerts.SummaryReport.Script.Alert.DataSource.v1010.ps1</ScriptName>
<ScriptBody>
#=================================================================================
# Script to gather ADCS alerts and close via on demand task
#
# Author: Kevin Justin
# v1.0
#=================================================================================
# Constants section - modify stuff here:
#=================================================================================
# Assign script name variable for use in event logging.
# ScriptName should be the same as the ID of the module that the script is contained in
$ScriptName = "Proactive.DailyTasks.ADCSAlerts.SummaryReport.Script.Alert.DataSource.v1010.ps1"
$EventID = "552"
#=================================================================================
# Starting Script section - All scripts get this
#=================================================================================
# Gather the start time of the script
$StartTime = Get-Date
#Set variable to be used in logging events
$whoami = whoami
# Load MOMScript API
$momapi = New-Object -comObject MOM.ScriptAPI
#Log script event that we are starting task
$momapi.LogScriptEvent($ScriptName,$EventID,0,"Script is starting. `n Running as ($whoami).")
#=================================================================================
# PropertyBag Script section - Monitoring scripts get this
#=================================================================================
# Load SCOM PropertyBag function
$bag = $momapi.CreatePropertyBag()
#=================================================================================
# Begin MAIN script section
#=================================================================================
$momapi.LogScriptEvent($ScriptName,$EventID,0,"`n Gather ADCS Alerts for date ($date).")
#For a simple example - get files in Windows Temp:
$date = get-date -uFormat "%Y-%m-%d"
# Grab past 24 hours
if ( (get-date).DayOfWeek -ne "Monday" )
{
$Time = [DateTime](Get-Date).AddDays(-1)
}
if ( (get-date).DayOfWeek -eq "Monday" )
{
$Time = [DateTime](Get-Date).AddDays(-3)
}
# Gather AD alerts
## Grab the MP, get the Monitors and Rules from the MP, then grab all alerts found inside the Monitors/Rules
$SCOMCoreMP = Get-SCOMManagementPack -DisplayName "Windows Server 2016+ Active Directory Certificate Services Monitoring"
$SCOMCoreRules = $SCOMCoreMP.GetRules()
$SCOMCoreMonitors = $SCOMCoreMP.GetMonitors()
$SCOMCoreReportAlerts = Get-SCOMAlert -ResolutionState (0..254) | ? { ($_.Name -in $SCOMCoreRules.DisplayName) -or ($_.Name -in $SCOMCoreMonitors.DisplayName) }
$SCOMCoreReportAlerts.Count
$SCOMCoreRuleAlerts = $SCOMCoreReportAlerts | ? { ( $_.Name -in $SCOMCoreRules.DisplayName) }
$SCOMCoreRuleAlerts.Count
$SCOMCoreMonitorAlerts = $SCOMCoreReportAlerts | ? { ($_.Name -in $SCOMCoreMonitors.DisplayName ) }
$SCOMCoreMonitorAlerts.Count
$SCOMCoreReportAlerts = $SCOMCoreReportAlerts | ? { ($_.Name -in $SCOMCoreRules.DisplayName) -or ($_.Name -in $SCOMCoreMonitors.DisplayName) }
$SCOMCoreReportAlerts.Count
$Test = $SCOMCoreReportAlerts.Count
$OpenADCSAlerts = $SCOMCoreReportAlerts
$OpenADCSAlerts.Count
$ClosedADCSAlerts = Get-SCOMAlert -ResolutionState 255 | ? { ($_.Name -in $SCOMCoreRules.DisplayName) -or ($_.Name -in $SCOMCoreMonitors.DisplayName) }
$ClosedADCSAlerts.Count
$ADCSAlerts = $SCOMCoreReportAlerts | select MonitoringObjectDisplayName,Description
#| select MonitoringObjectDisplayName,Description
$Test = $ADCSAlerts.count
if ( $Test -eq 0 )
{
$Message = "ZERO ADCS 2016+ alerts report for ($date)"
$momapi.LogScriptEvent($ScriptName,$EventID,0,"ZERO ADCS 2016+ alerts report for ($date).")
}
if ( $Test -gt 0 )
{
# Build report
$ADCSMessage = @()
$ADCSMessage += ""
# Show ADCS alerts by Time Raised,NetBiosComputerName,Message
#
$ADCSMessage += "# ADCS Alert report for $($date)"
$ADCSMessage += "#"
$ADCSMessage += "# Count of NEW ADCS alerts = $($ADCSAlerts.Count)"
$ADCSMessage += "#========================================================"
$ADCSMessage += ""
$ADCSMessage += "# ADCS Alert detail"
$ADCSMessage += "#============================================="
if ( $ADCSAlerts.Count -lt 10 )
{
$ADCSMessage += $ADCSAlerts | select NetBiosComputerName,TimeRaised,Description -auto -wrap
}
if ( $ADCSAlerts.Count -ge 10 )
{
$ADCSMessage += "The number of ADCS alerts exceeds 10 since the last report execution"
}
$ADCSMessage += "#========================"
$ADCSMessage += ""
}
$ADCSMessage
$ADCSMessage = $ADCSMessage | out-string
#============================================================
$Result = "GOOD"
$Message = "Daily ADCS alerts report for ($date)"
$momapi.LogScriptEvent($ScriptName,$EventID,0,"ADCS Monitors auto-closed for ($date). `n `n$ADCSMessage")
#$bag.AddValue('Result',$Result)
$bag.AddValue('Count',$Test)
$bag.AddValue('Message',$Message)
$bag.AddValue('Summary',$ADCSMessage)
# Return all bags
$bag
#=================================================================================
# End MAIN script section
# End of script section
#=================================================================================
#Log an event for script ending and total execution time.
$EndTime = Get-Date
$ScriptTime = ($EndTime - $StartTime).TotalSeconds
$momapi.LogScriptEvent($ScriptName,$EventID,0,"Script Completed. `n Script Runtime: ($ScriptTime) seconds.")
#=================================================================================
# End of script
</ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="PA">
<Node ID="Scheduler" />
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
</DataSourceModuleType>
<WriteActionModuleType ID="Proactive.DailyTasks.ADCSAlerts.Close.Script.Alert.WA" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element minOccurs="1" name="TimeoutSeconds" type="xsd:integer" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int" />
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="PSWA" TypeID="Windows!Microsoft.Windows.PowerShellWriteAction">
<ScriptName>Proactive.DailyTasks.ADCSAlerts.Close.Script.Alert.WA.v1010.ps1</ScriptName>
<ScriptBody>
#=================================================================================
# Script to gather ADCS alerts and close via on demand task
#
# Author: Kevin Justin
# v1.0
#=================================================================================
# Constants section - modify stuff here:
#=================================================================================
# Assign script name variable for use in event logging.
# ScriptName should be the same as the ID of the module that the script is contained in
$ScriptName = "Proactive.DailyTasks.ADCSAlerts.Close.Script.Alert.WA.v1010.ps1"
$EventID = "551"
#=================================================================================
# Starting Script section - All scripts get this
#=================================================================================
# Gather the start time of the script
$StartTime = Get-Date
#Set variable to be used in logging events
$whoami = whoami
# Load MOMScript API
$momapi = New-Object -comObject MOM.ScriptAPI
#Log script event that we are starting task
$momapi.LogScriptEvent($ScriptName,$EventID,0,"Script is starting. `n Running as ($whoami).")
#=================================================================================
# PropertyBag Script section - Monitoring scripts get this
#=================================================================================
# Load SCOM PropertyBag function
$bag = $momapi.CreatePropertyBag()
#=================================================================================
# Begin MAIN script section
#=================================================================================
#For a simple example - get files in Windows Temp:
$date = get-date -uFormat "%Y-%m-%d"
$Age = [DateTime](Get-Date).AddDays(-1)
# Grab past 24 hours
if ( (get-date).DayOfWeek -ne "Monday" )
{
$Time = [DateTime](Get-Date).AddDays(-1)
}
if ( (get-date).DayOfWeek -eq "Monday" )
{
$Time = [DateTime](Get-Date).AddDays(-3)
}
$momapi.LogScriptEvent($ScriptName,$EventID,0,"Gather Proactive DailyTasks ADCS Monitors close automation for ($date).")
$Message = "Proactive DailyTasks ADCS Monitors close automation for ($date)."
# Gather AD alerts
## Grab the MP, get the Monitors and Rules from the MP, then grab all alerts found inside the Monitors/Rules
$SCOMCoreMP = Get-SCOMManagementPack -DisplayName "Windows Server 2016+ Active Directory Certificate Services Monitoring"
$SCOMCoreRules = $SCOMCoreMP.GetRules()
$SCOMCoreMonitors = $SCOMCoreMP.GetMonitors()
$SCOMCoreReportAlerts = Get-SCOMAlert -ResolutionState (0..254) | ? { ($_.Name -in $SCOMCoreRules.DisplayName) -or ($_.Name -in $SCOMCoreMonitors.DisplayName) }
$SCOMCoreReportAlerts.Count
$SCOMCoreRuleAlerts = $SCOMCoreReportAlerts | ? { ( $_.Name -in $SCOMCoreRules.DisplayName) }
$SCOMCoreRuleAlerts.Count
$SCOMCoreMonitorAlerts = $SCOMCoreReportAlerts | ? { ($_.Name -in $SCOMCoreMonitors.DisplayName ) }
$SCOMCoreMonitorAlerts.Count
$SCOMCoreReportAlerts = $SCOMCoreReportAlerts | ? { ($_.Name -in $SCOMCoreRules.DisplayName) -or ($_.Name -in $SCOMCoreMonitors.DisplayName) }
$SCOMCoreReportAlerts.Count
$Test = $SCOMCoreReportAlerts.Count
$OpenADCS2012Alerts = $SCOMCoreReportAlerts
$OpenADCS2012Alerts.Count
$ClosedADCS2012Alerts = get-SCOMAlert -ResolutionState 255 | ? { ($_.Name -in $SCOMCoreRules.DisplayName) -or ($_.Name -in $SCOMCoreMonitors.DisplayName) }
$ClosedADCS2012Alerts.Count
$ADCSAlerts = $SCOMCoreReportAlerts | select MonitoringObjectDisplayName,Description
if ( $Test -eq 0 )
{
$Message = "ZERO ADCS 2016+ alerts to close for ($date)"
$momapi.LogScriptEvent($ScriptName,$EventID,0,"ZERO ADCS 2016+ alerts to close for ($date).")
}
if ( $Test -gt 0 )
{
#
# Build report
$ADCSComponentMessage = @()
$ADCSComponentMessage += ""
$ADCSComponentMessage += $Message
$ADCSComponentMessage += ""
$ADCSComponentMessage += "# ADCS Monitors auto-closed"
$ADCSComponentMessage += "#============================================================"
$ADCSComponentMessage += "# Total ADCS alerts = $($SCOMCoreReportAlerts.Count)"
$ADCSComponentMessage += "#"
$ADCSComponentMessage += "# Open alerts = $($OpenADCSAlerts.Count)"
$ADCSComponentMessage += "# Closed alerts = $($ClosedADCSAlerts.Count)"
$ADCSComponentMessage += "#"
$ADCSComponentMessage += "# Automation closed alerts = $($OpenADCSAlerts.Count)"
$ADCSComponentMessage += "#========================================="
$ADCSComponentMessage += ""
}
$ADCSComponentMessage
$ADCSComponentMessage = $ADCSComponentMessage | out-string
# Log data event before resetting monitors
#============================================================
$Result = "GOOD"
$Message = "Proactive DailyTasks ADCS Monitors close automation for ($date)"
$momapi.LogScriptEvent($ScriptName,$EventID,0,"Proactive DailyTasks ADCS Monitors close automation for ($date). `n `n$ADCSComponentMessage")
#$bag.AddValue('Result',$Result)
$bag.AddValue('Count',$Test)
$bag.AddValue('Message',$Message)
$bag.AddValue('Summary',$ADCSComponentMessage)
# Return all bags
$bag
#=================================================================================
# Reset Monitors Script base code modified
# Put ps1 in mgmtpacks folder
# https://sc.scomurr.com/scom-2012-monitor-reset-cleaning-up-the-environment/
# Download
# https://gallery.technet.microsoft.com/SCOM-2012-Batch-reset-63a17534
#Alternate
#https://gallery.technet.microsoft.com/scriptcenter/Auto-reset-script-for-d8b775ca
# Changed up logic to sort unique classes in mgmnt pack families.
# Added Age variable for monitors thanks to Aris Somatis - $Age specified in top level variables
# Cycling through monitors made reset loop huge ~650 monitors when only ~50 classes
# New logic reduced runtime from 8 minutes to roughly 8 seconds
#=================================================================================
# Write event for rule closure
$momapi.LogScriptEvent($ScriptName,$EventID,0,"Proactive DailyTasks ADCS Monitors reset started for ($date). `n `n $($ADCSMonitorsToAutoClose.Count) ")
if ( $SCOMCoreReportAlerts.Count -gt 0 )
{
# Get ADCS classes
$ADCSLibrary = Get-SCOMManagementPack -name "Microsoft.Windows.CertificateServices.Library"
#get-scomclass -ManagementPack $ADLibrary
$ADCSMonitoring = $SCOMCoreMP
#get-scomclass -ManagementPack $SCOMCoreMP | fl DisplayName,Name,ID
$ADCSDiscovery = Get-SCOMManagementPack -name Microsoft.Windows.ActiveDirectoryCertificateServices.2016.Discovery
#get-scomclass -ManagementPack $ADDiscovery | fl DisplayName,Name,ID
# ADCS pack naming
$ADCSClasses = @(Get-SCOMClass -ManagementPack $ADLibrary; Get-SCOMClass -ManagementPack $ADDiscovery; )
$ADCSClass = $ADCSClasses | sort -property Name -uniq
# Debug
$ADCSClass.Count