-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMECM_Servers_Health_Check_Reports.ps1
3314 lines (3270 loc) · 284 KB
/
MECM_Servers_Health_Check_Reports.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
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
#************************************************************************************************************************
$ErrorActionPreference = "SilentlyContinue"
Set-ExecutionPolicy remotesigned -Force $ErrorActionPreference
Clear-Host
Write-Host "*******************************************************************************" -foregroundcolor "Green"
Write-Host "File Name : MECM_Servers_Health_Check_Reports" -foregroundcolor "Green"
Write-Host "Purpose : MECM_Servers_Health_Check_Reports to sent an email" -foregroundcolor "Green"
Write-Host "Version : 01.00" -foregroundcolor "Green"
Write-Host "Date : 28/11/2017" -foregroundcolor "Green"
Write-Host "Author : Karthikeyan Anbarasu" -foregroundcolor "Green"
Write-Host "*******************************************************************************" -foregroundcolor "Green"
#**************************** Output Standard Color Code and Output Path Information ****
$OKColor = "Green"
$WarningColor = "Orange"
$CriticalColor = "Red"
$OfflineColor = "DarkRed"
$ToolName = "ConfigMgr_Servers_Health_Check_Reports"
#$OutputPath = split-path -parent $MyInvocation.MyCommand.Definition
#$OutputPath = "C:\Scripts\$ToolName"
$OutputPath = "D:\Scripts\$ToolName"
#$OutputPath = "E:\Scripts\$ToolName"
$ScriptValidationPath = "$OutputPath\$ToolName.exe"
#**************************** SSL SMTP Account Details *********************
$SMTPUserName = ""
$SMTPPassword = ""
#**************************** Script Path Validation Started ***************
If(-Not(Test-Path -path $ScriptValidationPath ))
{
Write-Host "Script Path Error :$OutputPath" -foregroundcolor "Red"
Write-Host "Script must be placed in path : $ScriptValidationPath" -foregroundcolor "Red"
Exit 1
}
#**************************** Script Path Validation End ***************
#**************************** Config File Creation and Others Information ***************
#$OutputPath = Split-Path -Parent $MyInvocation.MyCommand.Path
Add-Type -AssemblyName System.Windows.Forms
$ConfigFile = "$OutputPath\ConfigFile.xml"
$LogDir = "$OutputPath"
If(-Not(Test-Path -path $LogDir))
{
New-Item $LogDir -type directory | Out-null
}
If(Test-Path -path $ConfigFile)
{
[xml]$ConfigFile = Get-Content "$OutputPath\ConfigFile.xml"
}
Else
{
$ErrorConfigfile = "$Outputpath\Log\Error_Config_File_Missing.log"
Write-Host "Error: No ConfigXML File exists on Script Path :$OutputPath"
Add-Content $ErrorConfigfile -Value "Error: No ConfigXML File exists on Script Path :$OutputPath"
$Value = Read-Host "Do you want to create default ConfigXML File ? (Y/N)"
$Value = $Value.toupper()
If ($Value -eq "Y")
{
$ConfigFile = "$OutputPath\ConfigFile.xml"
Write-Host "Information: Default ConfigXML File is created on Script Path :$OutputPath"
Add-Content $ErrorConfigfile -Value "Information: Default ConfigXML File is created on Script Path :$OutputPath"
Write-Host "Information: Please change the ConfigXML File values as per Requirements"
Add-Content $ErrorConfigfile -Value "Information: Please change the ConfigXML File values as per Requirements"
$ConfigValue = @"
<Settings>
<CentralSettings>
<SCCMCentralDBName>SCCM_Central_DB_Name</SCCMCentralDBName>
<SCCMCentralDBServerName>SCCM_Central_DB_ServerName</SCCMCentralDBServerName>
</CentralSettings>
<SCCMSettings>
<ProjectName>Customer_Name</ProjectName>
<OutputFileName>MECM_Servers_Health_Check_Reports</OutputFileName>
<strServers>Server1,Server2</strServers>
<strMPServers>Server1,Server2</strMPServers>
<strServicesServers>Server1,Server2</strServicesServers>
<SiteCode>SiteCode</SiteCode>
<SMSProviderServerName>SMS_Provider_ServerName</SMSProviderServerName>
<SMSDBServerName>SCCM_DB_ServerName</SMSDBServerName>
<Certified>No</Certified>
</SCCMSettings>
<EmailSettings>
<TriggerMail>No</TriggerMail>
<SecureSSL>No</SecureSSL>
<SMTPServer>SMTP_Server_Name</SMTPServer>
<FromAddress>[email protected]</FromAddress>
<ToAddress></ToAddress>
<CCAddress></CCAddress>
<BCCAddress></BCCAddress>
</EmailSettings>
<HealthCheckCustomSettings>
<CheckOverAllSCCMSiteHierarchyRpt>Yes</CheckOverAllSCCMSiteHierarchyRpt>
<CheckOverAllSCCMSiteHierarchyDetailedRpt>Yes</CheckOverAllSCCMSiteHierarchyDetailedRpt>
<CheckOverAllSCCMSQLDBRpt>Yes</CheckOverAllSCCMSQLDBRpt>
<CheckOverAllSCCMSQLVersionRpt>Yes</CheckOverAllSCCMSQLVersionRpt>
<CheckOverAllSCCMServersRolesRpt>Yes</CheckOverAllSCCMServersRolesRpt>
<CheckOverAllSCCMSQLJobActivityRpt>Yes</CheckOverAllSCCMSQLJobActivityRpt>
<CheckWorkstationsClientHealthRpt>Yes</CheckWorkstationsClientHealthRpt>
<CheckServersClientHealthRpt>Yes</CheckServersClientHealthRpt>
<CheckServersAvailabilityRpt>Yes</CheckServersAvailabilityRpt>
<CheckServersDiskSpaceRpt>Yes</CheckServersDiskSpaceRpt>
<CheckServersMPRpt>Yes</CheckServersMPRpt>
<CheckSiteServersServicesRpt>Yes</CheckSiteServersServicesRpt>
<CheckSQLServerServicesRpt>Yes</CheckSQLServerServicesRpt>
<CheckBackupsRpt>Yes</CheckBackupsRpt>
<CheckAutoDeleteBadInbox>Yes</CheckAutoDeleteBadInbox>
<CheckInboxRpt>Yes</CheckInboxRpt>
<CheckIssueSiteServersRpt>Yes</CheckIssueSiteServersRpt>
<CheckOverAllSCCMServersSoftwareUpdateSyncRpt>Yes</CheckOverAllSCCMServersSoftwareUpdateSyncRpt>
<CheckNotCommunicatedRpt>Yes</CheckNotCommunicatedRpt>
<CheckCompRpt>Yes</CheckCompRpt>
<CheckWaitingContentRpt>Yes</CheckWaitingContentRpt>
<GenerateCSVRpt>Yes</GenerateCSVRpt>
</HealthCheckCustomSettings>
<DefaultSettings>
<SCCMManagedWorkstationsScopeCollectionID>SMS00001</SCCMManagedWorkstationsScopeCollectionID>
<SCCMManagedServersScopeCollectionID>SMS00001</SCCMManagedServersScopeCollectionID>
<InboxWarningCount>1000</InboxWarningCount>
<InboxCriticalCount>5000</InboxCriticalCount>
<WarningDiskSpacePercentage>15</WarningDiskSpacePercentage>
<CriticalDiskSpacePercentage>10</CriticalDiskSpacePercentage>
<CheckSiteBackup>Yes</CheckSiteBackup>
<CheckDBBackup>Yes</CheckDBBackup>
</DefaultSettings>
<HTMLSettings>
<ScriptDevelopedYear>2018</ScriptDevelopedYear>
<ScriptCheckPoint>Yes</ScriptCheckPoint>
<ScriptOwner>LAB</ScriptOwner>
<ScriptDevelopedBy>Karthikeyan Anbarasu</ScriptDevelopedBy>
<ScriptDeveloperEmailID>[email protected]</ScriptDeveloperEmailID>
<CompanyName>CompanyName</CompanyName>
<HeaderBGColor>#425563</HeaderBGColor>
<FooterBGColor>#425563</FooterBGColor>
<TableHeaderBGColor>#01A982</TableHeaderBGColor>
<TableHeaderRowBGColor>#CCCCCC</TableHeaderRowBGColor>
<TextColor>white</TextColor>
</HTMLSettings>
</Settings>
"@
Add-Content $ConfigFile -Value "$ConfigValue"
}
Exit 1
}
#****************************************************************************************
$SCCMCentralDBName = $ConfigFile.Settings.CentralSettings.SCCMCentralDBName
$SCCMCentralDBServerName = $ConfigFile.Settings.CentralSettings.SCCMCentralDBServerName
#****************************************************************************************
$ProjectName = $ConfigFile.Settings.SCCMSettings.ProjectName
$OutputFileName = $ConfigFile.Settings.SCCMSettings.OutputFileName
$strServers = $ConfigFile.Settings.SCCMSettings.strServers
$strMPServers = $ConfigFile.Settings.SCCMSettings.strMPServers
$strServicesServers = $ConfigFile.Settings.SCCMSettings.strServicesServers
$SiteCode = $ConfigFile.Settings.SCCMSettings.SiteCode
$SMSProviderServerName = $ConfigFile.Settings.SCCMSettings.SMSProviderServerName
$SMSDBServerName = $ConfigFile.Settings.SCCMSettings.SMSDBServerName
$Certified = $ConfigFile.Settings.SCCMSettings.Certified
#****************************************************************************************
$TriggerMail = $ConfigFile.Settings.EmailSettings.TriggerMail
$SecureSSL = $ConfigFile.Settings.EmailSettings.SecureSSL
$SMTPServer = $ConfigFile.Settings.EmailSettings.SMTPServer
$FromAddress = $ConfigFile.Settings.EmailSettings.FromAddress
$ToAddress = $ConfigFile.Settings.EmailSettings.ToAddress
$CCAddress = $ConfigFile.Settings.EmailSettings.CCAddress
$BCCAddress = $ConfigFile.Settings.EmailSettings.BCCAddress
#****************************************************************************************
$CheckOverAllSCCMSiteHierarchyRpt = $ConfigFile.Settings.HealthCheckCustomSettings.CheckOverAllSCCMSiteHierarchyRpt
$CheckOverAllSCCMSiteHierarchyDetailedRpt = $ConfigFile.Settings.HealthCheckCustomSettings.CheckOverAllSCCMSiteHierarchyDetailedRpt
$CheckOverAllSCCMSQLDBRpt = $ConfigFile.Settings.HealthCheckCustomSettings.CheckOverAllSCCMSQLDBRpt
$CheckOverAllSCCMSQLVersionRpt = $ConfigFile.Settings.HealthCheckCustomSettings.CheckOverAllSCCMSQLVersionRpt
$CheckOverAllSCCMServersRolesRpt = $ConfigFile.Settings.HealthCheckCustomSettings.CheckOverAllSCCMServersRolesRpt
$CheckOverAllSCCMSQLJobActivityRpt = $ConfigFile.Settings.HealthCheckCustomSettings.CheckOverAllSCCMSQLJobActivityRpt
$CheckWorkstationsClientHealthRpt = $ConfigFile.Settings.HealthCheckCustomSettings.CheckWorkstationsClientHealthRpt
$CheckServersClientHealthRpt = $ConfigFile.Settings.HealthCheckCustomSettings.CheckServersClientHealthRpt
$CheckServersAvailabilityRpt = $ConfigFile.Settings.HealthCheckCustomSettings.CheckServersAvailabilityRpt
$CheckServersDiskSpaceRpt = $ConfigFile.Settings.HealthCheckCustomSettings.CheckServersDiskSpaceRpt
$CheckServersMPRpt = $ConfigFile.Settings.HealthCheckCustomSettings.CheckServersMPRpt
$CheckSiteServersServicesRpt = $ConfigFile.Settings.HealthCheckCustomSettings.CheckSiteServersServicesRpt
$CheckSQLServerServicesRpt = $ConfigFile.Settings.HealthCheckCustomSettings.CheckSQLServerServicesRpt
$CheckBackupsRpt = $ConfigFile.Settings.HealthCheckCustomSettings.CheckBackupsRpt
$CheckAutoDeleteBadInbox = $ConfigFile.Settings.HealthCheckCustomSettings.CheckAutoDeleteBadInbox
$CheckInboxRpt = $ConfigFile.Settings.HealthCheckCustomSettings.CheckInboxRpt
$CheckIssueSiteServersRpt = $ConfigFile.Settings.HealthCheckCustomSettings.CheckIssueSiteServersRpt
$CheckOverAllSCCMServersSoftwareUpdateSyncRpt = $ConfigFile.Settings.HealthCheckCustomSettings.CheckOverAllSCCMServersSoftwareUpdateSyncRpt
$CheckNotCommunicatedRpt = $ConfigFile.Settings.HealthCheckCustomSettings.CheckNotCommunicatedRpt
$CheckCompRpt = $ConfigFile.Settings.HealthCheckCustomSettings.CheckCompRpt
$CheckWaitingContentRpt = $ConfigFile.Settings.HealthCheckCustomSettings.CheckWaitingContentRpt
$GenerateCSVRpt = $ConfigFile.Settings.HealthCheckCustomSettings.GenerateCSVRpt
#****************************************************************************************
$SCCMManagedWorkstationsScopeCollectionID = $ConfigFile.Settings.DefaultSettings.SCCMManagedWorkstationsScopeCollectionID
$SCCMManagedServersScopeCollectionID = $ConfigFile.Settings.DefaultSettings.SCCMManagedServersScopeCollectionID
$InboxWarningCount = $ConfigFile.Settings.DefaultSettings.InboxWarningCount
$InboxCriticalCount = $ConfigFile.Settings.DefaultSettings.InboxCriticalCount
$WarningDiskSpacePercentage = $ConfigFile.Settings.DefaultSettings.WarningDiskSpacePercentage
$CriticalDiskSpacePercentage = $ConfigFile.Settings.DefaultSettings.CriticalDiskSpacePercentage
$CheckSiteBackup = $ConfigFile.Settings.DefaultSettings.CheckSiteBackup
$CheckDBBackup = $ConfigFile.Settings.DefaultSettings.CheckDBBackup
#****************************************************************************************
$ScriptDevelopedYear = $ConfigFile.Settings.HTMLSettings.ScriptDevelopedYear
$ScriptCheckPoint = $ConfigFile.Settings.HTMLSettings.ScriptCheckPoint
$ScriptOwner = $ConfigFile.Settings.HTMLSettings.ScriptOwner
$ScriptDevelopedBy = $ConfigFile.Settings.HTMLSettings.ScriptDevelopedBy
$ScriptDeveloperEmailID = $ConfigFile.Settings.HTMLSettings.ScriptDeveloperEmailID
$CompanyName = $ConfigFile.Settings.HTMLSettings.CompanyName
$HeaderBGColor = $ConfigFile.Settings.HTMLSettings.HeaderBGColor
$FooterBGColor = $ConfigFile.Settings.HTMLSettings.FooterBGColor
$TableHeaderBGColor = $ConfigFile.Settings.HTMLSettings.TableHeaderBGColor
$TableHeaderRowBGColor = $ConfigFile.Settings.HTMLSettings.TableHeaderRowBGColor
$TextColor = $ConfigFile.Settings.HTMLSettings.TextColor
#**************************** Script Owner developer and email Information **************
$CompanyName = $CompanyName
$ScriptDevelopedBy = $ScriptDevelopedBy
$ScriptDeveloperEmailID = $ScriptDeveloperEmailID
#****************************************************************************************
#**************************** Adjust Services Infromation **************************************************************
$SCCMServices = "IISADMIN","W3SVC","Winmgmt","CcmExec","SMS_EXECUTIVE","SMS_SITE_COMPONENT_MANAGER","SMS_SITE_VSS_WRITER"
$SQLServices = "Winmgmt","CcmExec","SMS_EXECUTIVE","SMS_REPORTING_POINT","ReportServer","MSSQLSERVER"
#************************************************************************************************************************
Remove-Item -path "$OutputPath\*.html" -Force
Remove-Item -path "$OutputPath\*.CSV" -Force
$Report = "$OutputPath\MECM_Servers_Health_Check_Reports.html"
$CSVReport = "$OutputPath\MECM_Servers_Health_Check_Reports.CSV"
$Logfile = "$OutputPath\MECM_Servers_Health_Check_Reports.log"
#****************************************** Start ***********************************************
$a = Get-Date
$b = $a.AddDays(-1)
$b = $b.ToShortDateString()
$c = Get-Date
$c = $c.ToShortDateString()
$after = $b + " " + $StartTime
$before = $c + " " + $EndTime
$after = [datetime]$after
$before = [datetime]$before
#****************************************** End ***********************************************
If ($SCCMManagedWorkstationsScopeCollectionID.Length -eq 8)
{
If ($SCCMManagedWorkstationsScopeCollectionID -ne "")
{
If (($SCCMManagedWorkstationsScopeCollectionID.StartsWith("$SiteCode")) -or ($SCCMManagedWorkstationsScopeCollectionID.StartsWith("SMS")))
{
Write-Host "ConfigMgr Managed Workstations Scope CollectionID is : $SCCMManagedWorkstationsScopeCollectionID"
}
Else
{
Write-Host "Error: ConfigMgr Managed Workstations Scope CollectionID is not startwith $SiteCode or SMS in Config XML File."
Add-Content $logfile -Value "Error: ConfigMgr Managed Workstations Scope CollectionID is not startwith $SiteCode or SMS in Config XML File."
Add-Content $logfile -Value "****************** End Time: $(Get-Date) *******************"
Write-Host "****************** End Time: $(Get-Date) *******************"
Copy-Item -Path $logfile -Destination "C:\Windows\Temp\$OutputFileName.log" -Force
Exit 1
}
}
Else
{
Write-Host "Error: ConfigMgr Managed Workstations Scope CollectionID is Empty in Config XML File."
Add-Content $logfile -Value "Error: ConfigMgr Managed Workstations Scope CollectionID is Empty in Config XML File."
Add-Content $logfile -Value "****************** End Time: $(Get-Date) *******************"
Write-Host "****************** End Time: $(Get-Date) *******************"
Copy-Item -Path $logfile -Destination "C:\Windows\Temp\$OutputFileName.log" -Force
Exit 1
}
}
Else
{
Write-Host "Error: ConfigMgr Managed Workstations Scope CollectionID length is not 8 Character in Config XML File."
Add-Content $logfile -Value "Error: ConfigMgr Managed Workstations Scope CollectionID length is not 8 Character in Config XML File."
Add-Content $logfile -Value "****************** End Time: $(Get-Date) *******************"
Write-Host "****************** End Time: $(Get-Date) *******************"
Copy-Item -Path $logfile -Destination "C:\Windows\Temp\$OutputFileName.log" -Force
Exit 1
}
If ($SCCMManagedServersScopeCollectionID.Length -eq 8)
{
If ($SCCMManagedServersScopeCollectionID -ne "")
{
If (($SCCMManagedServersScopeCollectionID.StartsWith("$SiteCode")) -or ($SCCMManagedServersScopeCollectionID.StartsWith("SMS")))
{
Write-Host "ConfigMgr Managed Servers Scope CollectionID is : $SCCMManagedServersScopeCollectionID"
}
Else
{
Write-Host "Error: ConfigMgr Managed Servers Scope CollectionID is not startwith $SiteCode or SMS in Config XML File."
Add-Content $logfile -Value "Error: ConfigMgr Managed Servers Scope CollectionID is not startwith $SiteCode or SMS in Config XML File."
Add-Content $logfile -Value "****************** End Time: $(Get-Date) *******************"
Write-Host "****************** End Time: $(Get-Date) *******************"
Copy-Item -Path $logfile -Destination "C:\Windows\Temp\$OutputFileName.log" -Force
Exit 1
}
}
Else
{
Write-Host "Error: ConfigMgr Managed Servers Scope CollectionID is Empty in Config XML File."
Add-Content $logfile -Value "Error: ConfigMgr Managed Servers Scope CollectionID is Empty in Config XML File."
Add-Content $logfile -Value "****************** End Time: $(Get-Date) *******************"
Write-Host "****************** End Time: $(Get-Date) *******************"
Copy-Item -Path $logfile -Destination "C:\Windows\Temp\$OutputFileName.log" -Force
Exit 1
}
}
Else
{
Write-Host "Error: ConfigMgr Managed Servers Scope CollectionID length is not 8 Character in Config XML File."
Add-Content $logfile -Value "Error: ConfigMgr Managed Servers Scope CollectionID length is not 8 Character in Config XML File."
Add-Content $logfile -Value "****************** End Time: $(Get-Date) *******************"
Write-Host "****************** End Time: $(Get-Date) *******************"
Copy-Item -Path $logfile -Destination "C:\Windows\Temp\$OutputFileName.log" -Force
Exit 1
}
#****************************************************************************************
$SMSProvider = "\\$SMSProviderServerName\SMS_$SiteCode"
If(-Not(Test-Path "$SMSProvider"))
{
Write-Host "Error: SMS Provider ServerName or Sitecode is not properly mentioned in Config XML File or Your Account does not have sufficient Access"
Add-Content $logfile -Value "Error: SMS Provider ServerName or Sitecode is not properly mentioned in Config XML File or Your Account does not have sufficient Access"
Add-Content $logfile -Value "****************** End Time: $(Get-Date) *******************"
Write-Host "****************** End Time: $(Get-Date) *******************"
Copy-Item -Path $logfile -Destination "C:\Windows\Temp\$OutputFileName.log" -Force
Exit 1
}
#**************************** Script Path Validation End **************************************
$ReportTitle = "$ProjectName - ConfigMgr Health Check Reports - $(get-date -Format F)"
#************************************************************************************************************************
Function Get-DailyHTMLReport
{
Add-Content $logfile -Value "****************** Start Time: $(Get-Date) *******************"
Write-Host "****************** Start Time: $(Get-Date) *******************"
#Create a new report file to be emailed out
New-Item -ItemType File -Name $Report -Force | Out-Null
New-Item -ItemType File -Name $CSVReport -Force | Out-Null
#Write the HTML header information to file
writeHtmlHeader "$Path\$Report"
#Checking OverAll ConfigMgr Site Hierarchy Report
If ($CheckOverAllSCCMSiteHierarchyRpt -eq "Yes")
{
Add-Content $logfile -Value "01. $(Get-Date) - Checking Site Hierarchy Status"
Write-Host "01. $(Get-Date) - Checking Site Hierarchy Status"
#****************************************** End ***********************************************
$objConnection = New-Object -comobject ADODB.Connection
$objRecordset = New-Object -comobject ADODB.Recordset
$con = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Initial Catalog=$SCCMCentralDBName;Data Source=$SCCMCentralDBServerName"
$strSQL = @"
select distinct
(select COUNT(*) from v_SystemResourceList where RoleName = 'SMS Site System') as 'SCCM Servers Counts',
(select COUNT(*) from v_SystemResourceList where RoleName = 'SMS Site Server') as 'SCCM Site Counts',
(
select COUNT(*) from v_SystemResourceList Vrl
Inner Join V_site Vs on Vs.ServerName = Vrl.ServerName
Where Vrl.RoleName = 'SMS Site Server' and Vs.Type = 4 and Vs.ReportingSiteCode is not null
) as 'CAS Site Counts',
(
select COUNT(*) from v_SystemResourceList Vrl
Inner Join V_site Vs on Vs.ServerName = Vrl.ServerName
Where Vrl.RoleName = 'SMS Site Server' and Vs.Type = 2 and Vs.ReportingSiteCode is not null
) as 'PRI Site Counts',
(
select COUNT(*) from v_SystemResourceList Vrl
Inner Join V_site Vs on Vs.ServerName = Vrl.ServerName
Where Vrl.RoleName = 'SMS Site Server' and Vs.Type = 1 and Vs.ReportingSiteCode is not null
) as 'SEC Site Counts',
(select COUNT(*) from v_SystemResourceList where RoleName = 'SMS Management Point') as 'MP Servers Counts',
(select COUNT(*) from v_SystemResourceList where RoleName = 'SMS Distribution Point') as 'DP Servers Counts',
(select COUNT(*) from v_SystemResourceList where RoleName = 'SMS Software Update Point') as 'SUP Servers Counts',
(select COUNT(*) from v_SystemResourceList where RoleName = 'SMS SRS Reporting Point') as 'SSRS Servers Counts',
(select COUNT(*) from v_SystemResourceList where RoleName = 'SMS Provider') as 'SMSPro Servers Counts'
from v_SystemResourceList
"@
$objConnection.Open($con)
$objConnection.CommandTimeout = 0
# *********** Check If connection is open *******************
If($objConnection.state -eq 0)
{
Write-Host "Error: ConfigMgr Central DB ServerName or Central ConfigMgr DB Name is not properly mentioned in Config XML File or Your Account does not have sufficient Access"
Add-Content $logfile -Value "Error: Central ConfigMgr DB ServerName or Central ConfigMgr DB Name is not properly mentioned in Config XML File or Your Account does not have sufficient Access"
Exit 1
}
$rptheader=@"
<table width='100%'><tbody>
<tr bgcolor=$TableHeaderBGColor> <td> <b> <Font color = 'white'> Site Hierarchy Status </Font> </b> </td> </tr>
</table>
<table width='100%' border = 0 > <tbody>
<tr bgcolor=$TableHeaderRowBGColor>
<td width='10%'>SCCM Servers Counts</td>
<td width='10%'>SCCM Site Counts</td>
<td width='10%'>CAS Site Counts</td>
<td width='10%'>PRI Site Counts</td>
<td width='10%'>SEC Site Counts</td>
<td width='10%'>MP Servers Counts</td>
<td width='10%'>DP Servers Counts</td>
<td width='10%'>SUP Servers Counts</td>
<td width='10%'>SSRS Servers Counts</td>
<td width='10%'>SMSPro Servers Counts</td>
</tr>
</table>
<table>
"@
Add-Content "$Report" $rptheader
If ($GenerateCSVRpt -eq "Yes")
{
Add-Content $CSVReport -Value "Site Hierarchy Status"
Add-Content $CSVReport -Value "SCCM Servers Counts,SCCM Site Counts,CAS Site Counts,PRI Site Counts,SEC Site Counts,MP Servers Counts,DP Servers Counts,SUP Servers Counts,SSRS Servers Counts,SMSPro Servers Counts"
}
$z = 0
$i = 1
$y = 0
$objRecordset.Open($strSQL,$objConnection)
$objRecordset.MoveFirst()
$rows=$objRecordset.RecordCount
do
{
$value1 = $objRecordset.Fields.Item(0).Value
$value2 = $objRecordset.Fields.Item(1).Value
$value3 = $objRecordset.Fields.Item(2).Value
$value4 = $objRecordset.Fields.Item(3).Value
$value5 = $objRecordset.Fields.Item(4).Value
$value6 = $objRecordset.Fields.Item(5).Value
$value7 = $objRecordset.Fields.Item(6).Value
$value8 = $objRecordset.Fields.Item(7).Value
$value9 = $objRecordset.Fields.Item(8).Value
$value10 = $objRecordset.Fields.Item(9).Value
If ($value1)
{
$rpt = @"
<tr align='Center'>
<td width='10%'>$value1</td>
<td width='10%'>$value2</td>
<td width='10%'>$value3</td>
<td width='10%'>$value4</td>
<td width='10%'>$value5</td>
<td width='10%'>$value6</td>
<td width='10%'>$value7</td>
<td width='10%'>$value8</td>
<td width='10%'>$value9</td>
<td width='10%'>$value10</td>
</tr>
"@
Add-Content "$Report" $rpt
If ($GenerateCSVRpt -eq "Yes")
{
Add-Content $CSVReport -Value "$value1,$value2,$value3,$value4,$value5,$value6,$value7,$value8,$value9,$value10"
}
$i++
}
$objRecordset.MoveNext()
}
until ($objRecordset.EOF -eq $TRUE)
Add-Content "$Report" "</table>"
}
Else
{
Add-Content $logfile -Value "01. $(Get-Date) - Skipping Site Hierarchy Status"
Write-Host "01. $(Get-Date) - Skipping Site Hierarchy Status"
}
#Checking OverAll ConfigMgr Site Hierarchy Detailed Report
If ($CheckOverAllSCCMSiteHierarchyDetailedRpt -eq "Yes")
{
Add-Content $logfile -Value "02. $(Get-Date) - Checking Site Hierarchy Detailed Status"
Write-Host "02. $(Get-Date) - Checking Site Hierarchy Detailed Status"
#****************************************** End ***********************************************
$objConnection = New-Object -comobject ADODB.Connection
$objRecordset = New-Object -comobject ADODB.Recordset
$con = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Initial Catalog=$SCCMCentralDBName;Data Source=$SCCMCentralDBServerName"
$strSQL = @"
Select
V_Site.SiteCode as 'SiteCode',
V_Site.ReportingSiteCode as 'ReportTo',
V_Site.ServerName as 'ServerName',
V_Site.SiteName as 'SiteName',
CASE
WHEN V_Site.Type = 4 and V_Site.ReportingSiteCode is not null THEN 'Central'
WHEN V_Site.Type = 2 and V_Site.ReportingSiteCode ='' THEN 'Standalone Primary'
WHEN V_Site.Type = 2 and V_Site.ReportingSiteCode is not null THEN 'Primary'
WHEN V_Site.Type = 1 and V_Site.ReportingSiteCode is not null THEN 'Secondary'
ELSE 'Others' END as 'SiteType',
V_Site.InstallDir as 'Installed Directory',
CASE
WHEN V_Site.BuildNumber = '6487' THEN '2007'
WHEN V_Site.BuildNumber = '7711' THEN '2012 RTM'
WHEN V_Site.BuildNumber = '7804' THEN '2012 SP1'
WHEN V_Site.BuildNumber = '7958' THEN '2012 R2'
WHEN V_Site.BuildNumber = '8239' THEN '2012 R2 SP1'
WHEN V_Site.BuildNumber = '8325' THEN '1511'
WHEN V_Site.BuildNumber = '8355' THEN '1602'
WHEN V_Site.BuildNumber = '8412' THEN '1606'
WHEN V_Site.BuildNumber = '8458' THEN '1610'
WHEN V_Site.BuildNumber = '8498' THEN '1702'
WHEN V_Site.BuildNumber = '8540' THEN '1706'
WHEN V_Site.BuildNumber = '8577' THEN '1710'
ELSE '>18XX' END as 'SCCM Version',
V_Site.Version as 'Build Version'
from V_Site
"@
$objConnection.Open($con)
$objConnection.CommandTimeout = 0
# *********** Check If connection is open *******************
If($objConnection.state -eq 0)
{
Write-Host "Error: SCCM Central DB ServerName or Central SCCM DB Name is not properly mentioned in Config XML File or Your Account does not have sufficient Access"
Add-Content $logfile -Value "Error: Central ConfigMgr DB ServerName or Central ConfigMgr DB Name is not properly mentioned in Config XML File or Your Account does not have sufficient Access"
Exit 1
}
$rptheader=@"
<table width='100%'><tbody>
<tr bgcolor=$TableHeaderBGColor> <td> <b> <Font color = 'white'> Site Hierarchy Detailed Status </Font> </b> </td> </tr>
</table>
<table width='100%' border = 0 > <tbody>
<tr bgcolor=$TableHeaderRowBGColor>
<td width='5%'>SiteCode</td>
<td width='5%'>ReportTo</td>
<td width='20%'>ServerName</td>
<td width='20%'>Site Name</td>
<td width='10%'>Site Type</td>
<td width='20%'>Installed Directory</td>
<td width='10%'>SCCM Version</td>
<td width='10%'>Build Version</td>
</tr>
</table>
<table>
"@
Add-Content "$Report" $rptheader
If ($GenerateCSVRpt -eq "Yes")
{
Add-Content $CSVReport -Value "Site Hierarchy Detailed Status"
Add-Content $CSVReport -Value "SiteCode,ReportTo,ServerName,SiteName,SiteType,Installed Directory,SCCM Version,Build Version"
}
$z = 0
$i = 1
$y = 0
$objRecordset.Open($strSQL,$objConnection)
$objRecordset.MoveFirst()
$rows=$objRecordset.RecordCount
do
{
$value1 = $objRecordset.Fields.Item(0).Value
$value2 = $objRecordset.Fields.Item(1).Value
$value3 = $objRecordset.Fields.Item(2).Value
$value4 = $objRecordset.Fields.Item(3).Value
$value5 = $objRecordset.Fields.Item(4).Value
$value6 = $objRecordset.Fields.Item(5).Value
$value7 = $objRecordset.Fields.Item(6).Value
$value8 = $objRecordset.Fields.Item(7).Value
If ($value1)
{
$rpt = @"
<tr align='Center'>
<td width='5%'>$value1</td>
<td width='5%'>$value2</td>
<td width='20%'>$value3</td>
<td width='20%'>$value4</td>
<td width='10%'>$value5</td>
<td width='20%'>$value6</td>
<td width='10%'>$value7</td>
<td width='10%'>$value8</td>
</tr>
"@
Add-Content "$Report" $rpt
If ($GenerateCSVRpt -eq "Yes")
{
Add-Content $CSVReport -Value "$value1,$value2,$value3,$value4,$value5,$value6,$value7,$value8"
}
$i++
}
$objRecordset.MoveNext()
}
until ($objRecordset.EOF -eq $TRUE)
Add-Content "$Report" "</table>"
}
Else
{
Add-Content $logfile -Value "02. $(Get-Date) - Skipping Site Hierarchy Detailed Status"
Write-Host "02. $(Get-Date) - Skipping Site Hierarchy Detailed Status"
}
#Checking OverAll ConfigMgr SQL DB Report
If ($CheckOverAllSCCMSQLDBRpt -eq "Yes")
{
Add-Content $logfile -Value "03. $(Get-Date) - Checking ConfigMgr SQL Database Status"
Write-Host "03. $(Get-Date) - Checking ConfigMgr SQL Database Status"
#****************************************** End ***********************************************
$objConnection = New-Object -comobject ADODB.Connection
$objRecordset = New-Object -comobject ADODB.Recordset
$con = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Initial Catalog=$SCCMCentralDBName;Data Source=$SCCMCentralDBServerName"
$strSQL = @"
select
Sys.FILEID as 'FileID',
left(Sys.NAME,15) as 'DBName',
left(Sys.FILENAME,60) as 'DBFilePath',
convert(decimal(12,2),round(Sys.size/128.000,2)) as 'Filesize (MB)',
convert(decimal(12,2),round(fileproperty(Sys.name,'SpaceUsed')/128.000,2)) as 'UsedSpace (MB)',
convert(decimal(12,2),round((Sys.size-fileproperty(Sys.name,'SpaceUsed'))/128.000,2)) as 'FreeSpace (MB)',
convert(decimal(12,2),round(Sys.growth/128.000,2)) as 'GrowthSpace (MB)'
from dbo.sysfiles Sys
"@
$objConnection.Open($con)
$objConnection.CommandTimeout = 0
# *********** Check If connection is open *******************
If($objConnection.state -eq 0)
{
Write-Host "Error: ConfigMgr Central DB ServerName or Central ConfigMgr DB Name is not properly mentioned in Config XML File or Your Account does not have sufficient Access"
Add-Content $logfile -Value "Error: Central ConfigMgr DB ServerName or Central ConfigMgr DB Name is not properly mentioned in Config XML File or Your Account does not have sufficient Access"
Exit 1
}
$rptheader=@"
<table width='100%'><tbody>
<tr bgcolor=$TableHeaderBGColor> <td> <b> <Font color = 'white'> SCCM SQL Database Status </Font> </b> </td> </tr>
</table>
<table width='100%' border = 0 > <tbody>
<tr bgcolor=$TableHeaderRowBGColor>
<td width='10%'>FileID</td>
<td width='20%'>DBName</td>
<td width='30%'>DBFilePath</td>
<td width='10%'>Filesize (MB)</td>
<td width='10%'>UsedSpace (MB)</td>
<td width='10%'>FreeSpace (MB)</td>
<td width='10%'>GrowthSpace (MB)</td>
</tr>
</table>
<table>
"@
Add-Content "$Report" $rptheader
If ($GenerateCSVRpt -eq "Yes")
{
Add-Content $CSVReport -Value "SCCM SQL Database Status"
Add-Content $CSVReport -Value "FileID,DBName,DBFilePath,Filesize (MB),UsedSpace (MB),FreeSpace (MB),GrowthSpace (MB)"
}
$z = 0
$i = 1
$y = 0
$objRecordset.Open($strSQL,$objConnection)
$objRecordset.MoveFirst()
$rows=$objRecordset.RecordCount
do
{
$value1 = $objRecordset.Fields.Item(0).Value
$value2 = $objRecordset.Fields.Item(1).Value
$value3 = $objRecordset.Fields.Item(2).Value
$value4 = $objRecordset.Fields.Item(3).Value
$value5 = $objRecordset.Fields.Item(4).Value
$value6 = $objRecordset.Fields.Item(5).Value
$value7 = $objRecordset.Fields.Item(6).Value
If ($value1)
{
$rpt = @"
<tr align='Center'>
<td width='10%'>$value1</td>
<td width='20%'>$value2</td>
<td width='30%'>$value3</td>
<td width='10%'>$value4</td>
<td width='10%'>$value5</td>
<td width='10%'>$value6</td>
<td width='10%'>$value7</td>
</tr>
"@
Add-Content "$Report" $rpt
If ($GenerateCSVRpt -eq "Yes")
{
Add-Content $CSVReport -Value "$value1,$value2,$value3,$value4,$value5,$value6,$value7"
}
$i++
}
$objRecordset.MoveNext()
}
until ($objRecordset.EOF -eq $TRUE)
Add-Content "$Report" "</table>"
}
Else
{
Add-Content $logfile -Value "03. $(Get-Date) - Skipping SCCM SQL Database Status"
Write-Host "03. $(Get-Date) - Skipping SCCM SQL Database Status"
}
#Checking SQL Version Status
If ($CheckOverAllSCCMSQLVersionRpt -eq "Yes")
{
Add-Content $logfile -Value "04. $(Get-Date) - Checking SQL Version Status"
Write-Host "04. $(Get-Date) - Checking SQL Version Status"
#****************************************** End ***********************************************
$objConnection = New-Object -comobject ADODB.Connection
$objRecordset = New-Object -comobject ADODB.Recordset
$con = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Initial Catalog=$SCCMCentralDBName;Data Source=$SCCMCentralDBServerName"
$strSQL = @"
Select @@Version as 'SQL Server Version'
"@
$objConnection.Open($con)
$objConnection.CommandTimeout = 0
# *********** Check If connection is open *******************
If($objConnection.state -eq 0)
{
Write-Host "Error: SCCM Central DB ServerName or Central SCCM DB Name is not properly mentioned in Config XML File or Your Account does not have sufficient Access"
Add-Content $logfile -Value "Error: Central SCCM DB ServerName or Central SCCM DB Name is not properly mentioned in Config XML File or Your Account does not have sufficient Access"
Exit 1
}
$rptheader=@"
<table width='100%'><tbody>
<tr bgcolor=$TableHeaderBGColor> <td> <b> <Font color = 'white'> SQL Server Version Status </Font> </b> </td> </tr>
</table>
<table width='100%' border = 0 > <tbody>
<tr bgcolor=$TableHeaderRowBGColor>
<td width='100%'>SQL Server Version</td>
</tr>
</table>
<table>
"@
Add-Content "$Report" $rptheader
If ($GenerateCSVRpt -eq "Yes")
{
Add-Content $CSVReport -Value "SQL Server Version Status"
Add-Content $CSVReport -Value "SCCM SQL Server Version"
}
$z = 0
$i = 1
$y = 0
$objRecordset.Open($strSQL,$objConnection)
$objRecordset.MoveFirst()
$rows=$objRecordset.RecordCount
do
{
$value1 = $objRecordset.Fields.Item(0).Value
If ($value1)
{
$rpt = @"
<tr align='Center'>
<td width='10%'>$value1</td>
</tr>
"@
Add-Content "$Report" $rpt
If ($GenerateCSVRpt -eq "Yes")
{
Add-Content $CSVReport -Value "$value1"
}
$i++
}
$objRecordset.MoveNext()
}
until ($objRecordset.EOF -eq $TRUE)
Add-Content "$Report" "</table>"
}
Else
{
Add-Content $logfile -Value "04. $(Get-Date) - Skipping SQL Version Status"
Write-Host "04. $(Get-Date) - Skipping SQL Version Status"
}
#Checking ConfigMgr Roles Status
If ($CheckOverAllSCCMServersRolesRpt -eq "Yes")
{
Add-Content $logfile -Value "05. $(Get-Date) - Checking ConfigMgr Roles Status"
Write-Host "05. $(Get-Date) - Checking ConfigMgr Roles Status"
#****************************************** End ***********************************************
$objConnection = New-Object -comobject ADODB.Connection
$objRecordset = New-Object -comobject ADODB.Recordset
$con = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Initial Catalog=$SCCMCentralDBName;Data Source=$SCCMCentralDBServerName"
$strSQL = @"
select distinct
(select COUNT(*) from v_SystemResourceList where RoleName = 'SMS Site System') as 'SiteSys',
(select COUNT(*) from v_SystemResourceList where RoleName = 'SMS Component Server') as 'CompSer',
(select COUNT(*) from v_SystemResourceList where RoleName = 'SMS Site Server') as 'SiteSer',
(select COUNT(*) from v_SystemResourceList where RoleName = 'SMS Management Point') as 'MP',
(select COUNT(*) from v_SystemResourceList where RoleName = 'SMS Distribution Point') as 'DP',
(select COUNT(*) from v_SystemResourceList where RoleName = 'SMS SQL Server') as 'SQL',
(select COUNT(*) from v_SystemResourceList where RoleName = 'SMS Software Update Point') as 'SUP',
(select COUNT(*) from v_SystemResourceList where RoleName = 'SMS SRS Reporting Point') as 'SSRS',
(select COUNT(*) from v_SystemResourceList where RoleName = 'SMS Reporting Point') as 'RPT',
(select COUNT(*) from v_SystemResourceList where RoleName = 'SMS Fallback Status Point') as 'FSP',
(select COUNT(*) from v_SystemResourceList where RoleName = 'SMS Server Locator Point') as 'SLP',
(select COUNT(*) from v_SystemResourceList where RoleName = 'SMS PXE Service Point') as 'PXE',
(select COUNT(*) from v_SystemResourceList where RoleName = 'SMS System Health Validator') as 'SysVal',
(select COUNT(*) from v_SystemResourceList where RoleName = 'SMS State Migration Point') as 'SMP',
(select COUNT(*) from v_SystemResourceList where RoleName = 'SMS Notification Server') as 'NotiSer',
(select COUNT(*) from v_SystemResourceList where RoleName = 'SMS Provider') as 'SMSPro',
(select COUNT(*) from v_SystemResourceList where RoleName = 'SMS Application Web Service') as 'WebSer',
(select COUNT(*) from v_SystemResourceList where RoleName = 'SMS Portal Web Site') as 'WebSite',
(select COUNT(*) from v_SystemResourceList where RoleName = 'SMS Branch distribution point') as 'BranDP'
from v_SystemResourceList
"@
$objConnection.Open($con)
$objConnection.CommandTimeout = 0
# *********** Check If connection is open *******************
If($objConnection.state -eq 0)
{
Write-Host "Error: SCCM Central DB ServerName or Central SCCM DB Name is not properly mentioned in Config XML File or Your Account does not have sufficient Access"
Add-Content $logfile -Value "Error: Central SCCM DB ServerName or Central SCCM DB Name is not properly mentioned in Config XML File or Your Account does not have sufficient Access"
Exit 1
}
$rptheader=@"
<table width='100%'><tbody>
<tr bgcolor=$TableHeaderBGColor> <td> <b> <Font color = 'white'> ConfigMgr Roles Status </Font> </b> </td> </tr>
</table>
<table width='100%' border = 0 > <tbody>
<tr bgcolor=$TableHeaderRowBGColor>
<td width='5%'>SiteSys</td>
<td width='5%'>CompSer</td>
<td width='5%'>SiteSer</td>
<td width='5%'>MP</td>
<td width='5%'>DP</td>
<td width='5%'>SQL</td>
<td width='5%'>SUP</td>
<td width='5%'>SSRS</td>
<td width='5%'>RPT</td>
<td width='5%'>FSP</td>
<td width='5%'>SLP</td>
<td width='5%'>PXE</td>
<td width='5%'>SysVal</td>
<td width='5%'>SMP</td>
<td width='5%'>NotiSer</td>
<td width='5%'>SMSPro</td>
<td width='5%'>WebSer</td>
<td width='5%'>WebSite</td>
<td width='5%'>BranDP</td>
</tr>
</table>
<table>
"@
Add-Content "$Report" $rptheader
If ($GenerateCSVRpt -eq "Yes")
{
Add-Content $CSVReport -Value "ConfigMgr Roles Status"
Add-Content $CSVReport -Value "SiteSys,CompSer,SiteSer,MP,DP,SQL,SUP,SSRS,RPT,FSP,SLP,PXE,SysVal,SMP,NotiSer,SMSPro,WebSer,WebSite,BranDP"
}
$z = 0
$i = 1
$y = 0
$objRecordset.Open($strSQL,$objConnection)
$objRecordset.MoveFirst()
$rows=$objRecordset.RecordCount
do
{
$value1 = $objRecordset.Fields.Item(0).Value
$value2 = $objRecordset.Fields.Item(1).Value
$value3 = $objRecordset.Fields.Item(2).Value
$value4 = $objRecordset.Fields.Item(3).Value
$value5 = $objRecordset.Fields.Item(4).Value
$value6 = $objRecordset.Fields.Item(5).Value
$value7 = $objRecordset.Fields.Item(6).Value
$value8 = $objRecordset.Fields.Item(7).Value
$value9 = $objRecordset.Fields.Item(8).Value
$value10 = $objRecordset.Fields.Item(9).Value
$value11 = $objRecordset.Fields.Item(10).Value
$value12 = $objRecordset.Fields.Item(11).Value
$value13 = $objRecordset.Fields.Item(12).Value
$value14 = $objRecordset.Fields.Item(13).Value
$value15 = $objRecordset.Fields.Item(14).Value
$value16 = $objRecordset.Fields.Item(15).Value
$value17 = $objRecordset.Fields.Item(16).Value
$value18 = $objRecordset.Fields.Item(17).Value
$value19 = $objRecordset.Fields.Item(18).Value
If ($value1)
{
$rpt = @"
<tr align='Center'>
<td width='5%'>$value1</td>
<td width='5%'>$value2</td>
<td width='5%'>$value3</td>
<td width='5%'>$value4</td>
<td width='5%'>$value5</td>
<td width='5%'>$value6</td>
<td width='5%'>$value7</td>
<td width='5%'>$value8</td>
<td width='5%'>$value9</td>
<td width='5%'>$value10</td>
<td width='5%'>$value11</td>
<td width='5%'>$value12</td>
<td width='5%'>$value13</td>
<td width='5%'>$value14</td>
<td width='5%'>$value15</td>
<td width='5%'>$value16</td>
<td width='5%'>$value17</td>
<td width='5%'>$value18</td>
<td width='5%'>$value19</td>
</tr>
"@
Add-Content "$Report" $rpt
If ($GenerateCSVRpt -eq "Yes")
{
Add-Content $CSVReport -Value "$value1,$value2,$value3,$value4,$value5,$value6,$value7,$value8,$value9,$value10,$value11,$value12,$value13,$value14,$value15,$value16,$value17,$value18,$value19"
}
$i++
}
$objRecordset.MoveNext()
}
until ($objRecordset.EOF -eq $TRUE)
Add-Content "$Report" "</table>"
}
Else
{
Add-Content $logfile -Value "05. $(Get-Date) - Skipping ConfigMgr Roles Status"
Write-Host "05. $(Get-Date) - Skipping ConfigMgr Roles Status"
}
#Checking SQL Job Activity Status
If ($CheckOverAllSCCMSQLJobActivityRpt -eq "Yes")
{
Add-Content $logfile -Value "06. $(Get-Date) - Checking SQL Job Activity Status"
Write-Host "06. $(Get-Date) - Checking SQL Job Activity Status"
#****************************************** End ***********************************************
$objConnection = New-Object -comobject ADODB.Connection
$objRecordset = New-Object -comobject ADODB.Recordset
$con = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Initial Catalog=msdb;Data Source=$SCCMCentralDBServerName"
$strSQL = @"
Select distinct j.Name as 'Job Name',
jh.server as 'ServerName',
case j.enabled
when 1 then 'Enable'
when 0 then 'Disable'
end as 'Job Status',
CONVERT(date,CONVERT(varchar(10),jh.run_date,103)) as 'Executed Date',
case jh.run_status
when 0 then 'Failed'
when 1 then 'Successful'
when 2 then 'Retry'
when 3 then 'Cancelled'
when 4 then 'In Progress'
end as 'Job Execution Status'
from sysJobHistory jh, sysJobs j
where j.job_id = jh.job_id and jh.run_date =
(select max(hi.run_date) from sysJobHistory hi where jh.job_id = hi.job_id)
order by 4 desc
"@
$objConnection.Open($con)
$objConnection.CommandTimeout = 0
# *********** Check If connection is open *******************
If($objConnection.state -eq 0)
{
Write-Host "Error: SCCM Central DB ServerName or Central SCCM DB Name is not properly mentioned in Config XML File or Your Account does not have sufficient Access"
Add-Content $logfile -Value "Error: Central SCCM DB ServerName or Central SCCM DB Name is not properly mentioned in Config XML File or Your Account does not have sufficient Access"
Exit 1
}
$rptheader=@"
<table width='100%'><tbody>
<tr bgcolor=$TableHeaderBGColor> <td> <b> <Font color = 'white'> SQL Job Activity Status </Font> </b> </td> </tr>
</table>
<table width='100%' border = 0 > <tbody>
<tr bgcolor=$TableHeaderRowBGColor>
<td width='20%'>Job Name</td>
<td width='20%'>ServerName</td>
<td width='20%'>Job Status</td>
<td width='20%'>Executed Date</td>
<td width='15%'>Job Execution Status</td>
<td width='5%'>Status</td>
</tr>
</table>
<table>
"@
Add-Content "$Report" $rptheader
If ($GenerateCSVRpt -eq "Yes")
{
Add-Content $CSVReport -Value "SQL Job Activity Status"
Add-Content $CSVReport -Value "Job Name,ServerName,Job Status,Executed Date,Job Execution Status,Status"
}
$z = 0
$i = 1
$y = 0
$objRecordset.Open($strSQL,$objConnection)
$objRecordset.MoveFirst()
$rows=$objRecordset.RecordCount
do
{
$value1 = $objRecordset.Fields.Item(0).Value
$value2 = $objRecordset.Fields.Item(1).Value
$value3 = $objRecordset.Fields.Item(2).Value
$value4 = $objRecordset.Fields.Item(3).Value
$value5 = $objRecordset.Fields.Item(4).Value
If ($value1)
{
If ($value3 -eq "Enable" -and $value5 -eq "Failed")
{
$Status = "Critcal"
$Color = $CriticalColor
}
Else
{
$Status = "Ok"
$Color = $OKColor
}
$rpt = @"
<tr align='Center'>
<td width='20%' align='left'>$value1</td>
<td width='20%'>$value2</td>
<td width='20%'>$value3</td>
<td width='20%'>$value4</td>
<td width='15%'>$value5</td>
<td width='5%' align='center' bgcolor='$Color'> <Font color ='$TextColor'> $Status </Font> </td>
</tr>
"@
Add-Content "$Report" $rpt
If ($GenerateCSVRpt -eq "Yes")
{
Add-Content $CSVReport -Value "$value1,$value2,$value3,$value4,$value5,$Status"
}
$i++
}
$objRecordset.MoveNext()
}
until ($objRecordset.EOF -eq $TRUE)
Add-Content "$Report" "</table>"
}
Else
{
Add-Content $logfile -Value "06. $(Get-Date) - Skipping SQL Job Activity Status"
Write-Host "06. $(Get-Date) - Skipping SQL Job Activity Status"
}