-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSCCM-CheckPrerequisites-v2.0.ps1
1275 lines (1070 loc) · 41.3 KB
/
SCCM-CheckPrerequisites-v2.0.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
#Functions section
Function Write-Time( )
{
<#
.SYNOPSIS
Function to diplay a timestamped message in the console.
.DESCRIPTION
Function designed to display a message preeceded by a timestamp of when the message as been displayed.
.PARAMETER msg
This is the content that need to be displayed with a timestamp. It must be a string.
.PARAMETER value
This is the type of your message :
0 - Normal
1 - Success
2 - Warning
3 - Error
.EXAMPLE
Write-Time("Hello World") will return "[17/07/2017 13:39:07] Hello World"
Write-Time("Hello World", 3) will display the same message as above, with a red foreground color : "[17/07/2017 13:39:07] Hello World"
#>
param( [string] $msg, [int]$type )
if ($type -ne 0) {
switch ($type)
{
1 { Write-Host "[$(Get-Date -Format 'dd/MM/yyyy HH:mm:ss')] $msg" -foregroundcolor Green }
2 { Write-Host "[$(Get-Date -Format 'dd/MM/yyyy HH:mm:ss')] $msg" -foregroundcolor Yellow }
3 { Write-Host "[$(Get-Date -Format 'dd/MM/yyyy HH:mm:ss')] $msg" -foregroundcolor Red }
default { Write-Host "[$(Get-Date -Format 'dd/MM/yyyy HH:mm:ss')] $msg" -foregroundcolor White }
}
}
else {
Write-Host "[$(Get-Date -Format 'dd/MM/yyyy HH:mm:ss')] $msg"
}
}
Function Test-InternetConnection {
Test-Connection -ComputerName "http://www.google.com" -count 1 -quiet
}
Function Get-Disks-Infos()
{
$harddisks = Get-WmiObject –query “SELECT * from win32_logicaldisk”
$res = '<ul>'
if ($harddisks.Count -eq 0) {
$res = "<ul>No hard drives found on this computer"
}
else {
foreach ($disk in $harddisks) {
#if ($disk.VolumeName -ne "" -and $disk.Size -gt 0) {
$res = ($res + ('<li>' + $disk.VolumeName + ' : ' + [Math]::Floor($disk.Size / 1000000000 ) ).ToString() + 'Go (' + ([Math]::Floor($disk.FreeSpace / 1000000000 ) ).ToString() + 'Go Free)</li>')
#}
#else {
# $res = "<li>Unknown Disk</li>"
#}
}
}
$res = $res + '</ul>'
return $res
}
Function Get-SCCMUsedVersion {
<#
.SYNOPSIS
Get the Microsoft System Center Client application installed and used on the local computer
.DESCRIPTION
This function will look for CcmExec.exe in the defautl installation path for this product wether you are on a x86 computer or not.
Based on the property of the Outlook.exe file it will determine the Outlook version used.
.EXAMPLE
Get-SCCMUsedVersion
Will prompt the outlook version installed and used on the local computer.
#>
[CmdletBinding()]
param ()
$SCCMPath = (Resolve-Path 'C:\Windows\CCM\CcmExec.exe').Path
$SCCMVersion = ((Get-ItemProperty $SCCMPath).VersionInfo)
Write-Verbose -Message "[$(Get-Date -Format 'dd/MM/yyyy HH:mm:ss')] $($MyInvocation.MyCommand.Name) - Found SCCM Client version $SCCMVersion on the computer"
if ($SCCMVersion -match '5.0.8325'){
Write-Output 'SCCM1511'
}
elseif ($SCCMVersion -match '5.00.8355'){
Write-Output 'SCCM1602'
}
elseif ($SCCMVersion -match '5.00.8412'){
Write-Output 'SCCM1606'
}
elseif ($SCCMVersion -match '5.00.8458'){
Write-Output 'SCCM1610'
}
elseif ($SCCMVersion -match '5.00.8498'){
Write-Output 'SCCM1702'
}
}
Function Get-SCInstalledVersion
{
<#
.SYNOPSIS
Get the SoftwareCenter application installed on the local computer
.DESCRIPTION
This function will look for SoftwareCenter in the default installation path for those products wether you are on a x86 computer or not.
.EXAMPLE
Get-SCInstalledVersion
Will prompt the SoftwareCenter installed or not on the local computer.
#>
[CmdletBinding()]
param(
$OCSInstallationPath = 'C:\Windows\CCM\ClientUX\SCClient.exe'
)
if(Test-Path $OCSInstallationPath){
Write-Verbose -Message "[$(Get-Date -Format 'dd/MM/yyyy HH:mm:ss')] $($MyInvocation.MyCommand.Name) - Found SoftwareCenter on the computer"
$displayedName = 'Yes'
}
else {
Write-Verbose -Message "[$(Get-Date -Format 'dd/MM/yyyy HH:mm:ss')] $($MyInvocation.MyCommand.Name) - No Microsoft SoftwareCenter found on the computer"
$displayedName = 'No'
}
Write-Output $displayedName
}
Function Test-ActiveDirectoryLabels
{
<#
.SYNOPSIS
Test if the Active Directory user account exist.
.DESCRIPTION
Test if the Active Directory user account exist.
The test will proceed to a Directory Service Search matching the SAMAccountName of the user.
.EXAMPLE
Test-ActiveDirectoryLabels
Will show if the Active Directory user account exist or not.
#>
[CmdletBinding()]
param ()
$infonContent = ((New-Object DirectoryServices.DirectorySearcher "(&(ObjectCategory=user)(ObjectClass=Person)(SamAccountName=$env:USERNAME))").FindAll())
if(!$infonContent){
Write-Verbose -Message "[$(Get-Date -Format 'dd/MM/yyyy HH:mm:ss')] $($MyInvocation.MyCommand.Name) - User does not have the Active Directory 'info' attributs set for COMETE NG"
Write-Output "User account $env:USERNAME <a class='text-danger'>not exist</a> in Active Directory)."
}
else {
Write-Verbose -Message "[$(Get-Date -Format 'dd/MM/yyyy HH:mm:ss')] $($MyInvocation.MyCommand.Name) - User exist in the Active Directory"
Write-Output "User account $env:USERNAME <a class='text-success'>exist</a> in Active Directory."
}
}
Function Ping-Check($computer, $iPingRetryWait, $iPingRetryTimes)
{
$bPing = $false
$ping = New-Object Net.NetworkInformation.Ping
$PingResult = $ping.send($computer)
if ($PingResult.Status.Tostring().ToLower() -eq "success")
{
$bPing = $true
} else {
#if first attemp failed, wait for number of seconds that's defined in XML file and try again
Start-Sleep $iPingRetryWait
#attemp to ping few more times (defined in XML file)
For ($i=1; $i -le $iPingRetryTimes; $i++)
{
$PingResult = $ping.send($computer)
if ($PingResult.Status.Tostring().ToLower() -eq "success")
{
$bPing = $true
}
}
}
return $bPing
}
Function Test-UrlResolution {
<#
.SYNOPSIS
Test URL resolution based on DNS query
.DESCRIPTION
Test URL resolution based on DNS query
.EXAMPLE
Test-UrlResolution -Urls $($entry.Urls -split ',')
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $false)]
[string[]]$Urls
)
foreach ($url in $Urls) {
if($url.ToLower().EndsWith('*')) {
$subDomain = ($url.split('.'))[0]
$userDNSDomain = $Env:USERDNSDOMAIN
$url = $subDomain + '.' + $userDNSDomain
}
Write-Time -msg "$($MyInvocation.MyCommand.Name) - Testing the DNS resolution of URL: $url..."
try {
if([System.Net.DNS]::GetHostEntry($url)){
$urlResults = New-Object -TypeName PSObject -Property @{
url = $url
DnsResolution = $true
}
Write-Time -msg "$($MyInvocation.MyCommand.Name) - $url resolved (OK)" -type 1
$global:success++
}
else {
$urlResults = New-Object -TypeName PSObject -Property @{
url = $url
DnsResolution = $false
}
Write-Time -msg "$($MyInvocation.MyCommand.Name) - $url did not resolved (KO)" -type 3
$global:failure++
}
}
catch {
$urlResults = New-Object -TypeName PSObject -Property @{
url = $url
DnsResolution = $false
}
Write-Time -msg "$($MyInvocation.MyCommand.Name) - $url did not resolved (KO)" -type 3
$global:failure++
}
Write-Output $urlResults
}
}
Function Test-VipPorts {
<#
.SYNOPSIS
Tests port connection for a specific IP address
.DESCRIPTION
This function is used to verify connection to specified ports for specified IP Address
.EXAMPLE
Test-VipPorts -Vips $($entry.Vips -split ',') -Ports $($entry | Select-Object -ExpandProperty Ports)
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string[]]$Vips,
[Parameter(Mandatory = $true)]
[string]$Port,
[Parameter(Mandatory = $true)]
[ValidateSet('TCP', 'UDP')]
[string]$Protocol,
[Parameter(Mandatory = $false)]
[String]$Timeout = 3000
)
foreach ($vip in $($Vips -split ',')){
if ($Protocol -eq 'TCP') {
$tcpClient = New-Object system.Net.Sockets.TcpClient
try {
$iar = $tcpClient.BeginConnect($vip,$Port,$null,$null)
$wait = $iar.AsyncWaitHandle.WaitOne($Timeout,$false)
if(!$wait){
$tcpClient.Close()
$object = New-Object -TypeName PSObject -Property @{
IP = $vip
Port = $Port
Protocol = $Protocol
GetResponce = $False
}
Write-Time -msg "$($MyInvocation.MyCommand.Name) - Port: $Port $Protocol, on IP: $Vip, Connection attempt timed out (KO)" -type 3
$global:failure++
}
else {
if($tcpClient.Connected) {
$tcpClient.Close()
$object = New-Object -TypeName PSObject -Property @{
IP = $vip
Port = $Port
Protocol = $Protocol
GetResponce = $True
}
Write-Time -msg "$($MyInvocation.MyCommand.Name) - Port: $Port $Protocol, on IP: $Vip, is available (OK)" -type 1
$global:success++
}
else {
$object = New-Object -TypeName PSObject -Property @{
IP = $vip
Port = $Port
Protocol = $Protocol
GetResponce = $False
}
Write-Time -msg "$($MyInvocation.MyCommand.Name) - Port: $Port $Protocol, on IP: $Vip, is not available (KO)" -type 3
$global:failure++
}
}
}
catch {
$object = New-Object -TypeName PSObject -Property @{
IP = $vip
Port = $Port
Protocol = $Protocol
GetResponce = $False
}
Write-Time -msg "$($MyInvocation.MyCommand.Name) - Port: $Port $Protocol, on IP: $Vip, is not available (KO)" -type 3
$global:failure++
}
Write-Output $object
}
elseif ($Protocol -eq 'UDP') {
$test = Test-UDPwithPortQry -ComputerName $vip -Protocol $Protocol -Port $Port -PortQryPath $Port
$object = New-Object -TypeName PSObject -Property @{
IP = $vip
Port = $Port
Protocol = $Protocol
GetResponce = $test
}
Write-Output $object
}
}
}
Function Test-UDPwithPortQry {
param (
[Parameter(Mandatory=$true)]
[string]$ComputerName,
[Parameter(Mandatory=$true)]
[string]$Protocol,
[Parameter(Mandatory=$true)]
[int]$Port,
[Parameter(Mandatory=$false)]
[string]$PortQryPath = $PortQryLocation
)
if ($PortQryPath -ne "") {
$portQryBin = Test-Path $PortQryPath
}
else {
$portQryBin = False
}
if ($portQryBin) {
[string]$command = $PortQryPath
$portQuery = & $command -n $ComputerName -p $Protocol -e $Port
if ($portQuery -match "$($Protocol) port $($Port) is LISTENING") {
Write-Time -msg "$($MyInvocation.MyCommand.Name) - $($Protocol) port $($Port) is LISTENING" -type 1
$result = 'TRUE'
}
else {
Write-Time -msg "$($MyInvocation.MyCommand.Name) - $($Protocol) port $($Port) is not found as LISTENING (may be filtered)" -type 2
$result = 'FALSE'
}
}
else {
Write-Time -msg "$($MyInvocation.MyCommand.Name) - PortQry has not been found, unable to test UDP port response" -type 3
$result = 'NOT TESTED'
}
Write-Output $result
}
################### ~~~~~~~~~~~~~~~~~~~~~~~~~~~|| SCCM Health Cheking Main Script ||~~~~~~~~~~~~~~~~~~~~~~~~~~~ ###################
### ~~~~~~~~ Windows notification : Beginning of the checking process
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$objNotifyIcon = New-Object System.Windows.Forms.NotifyIcon
$objNotifyIcon.Icon = "C:\Users\d594416\Documents\Work\Scripts\SCCM-CheckPrerequisites-v2.0\RESSOURCES\favicon_0.ico"
$objNotifyIcon.BalloonTipIcon = "Info"
$objNotifyIcon.BalloonTipText = "Starting SCCM Prerequisites Cheking..."
$objNotifyIcon.BalloonTipTitle = "SCCM Check Prerequisites"
$objNotifyIcon.Visible = $True
$objNotifyIcon.ShowBalloonTip(1000)
$begintime = Get-Date
Write-Time("Starting SCCM Prerequisites Cheking...")
$actiondone = 0
$actionsuccess = 0
$actionfail = 0
### ~~~~~~~~ Trying to find the settings.xml file
$settingfound = $FALSE
Try {
$scriptRoot = Split-Path (Resolve-Path $myInvocation.MyCommand.Path)
$ConfigXML = Join-Path $scriptRoot "settings.xml"
$xml = [xml](get-content $configXML)
Write-Time -msg "Successfully found settings.xml" -type 1
$actionsuccess++
$settingfound = $TRUE
}
Catch {
Write-Time -msg "Can't access settings.xml. Follow the instructions in README" -type 3
$actionfail++
}
$actiondone++
### ~~~~~~~~ Getting infos from the current user on the current PC
Write-Time("Getting user informations...")
Try {
$SCCMVersion = Get-SCCMUsedVersion
$filepath = $PSScriptRoot + '\REPORTS\SCCM-CheckPrerequisites-' + $(Get-Date -Format 'dd-MM-yyyy-HH-mm-ss') +'.html'
$date = Get-Date -format "dd/MM/yyyy HH:mm:ss"
$servername = $env:COMPUTERNAME
$company = $xml.Configuration.Company;
$IMVersion = Get-SCInstalledVersion
$ADCheck = Test-ActiveDirectoryLabels
$cpu = Get-WmiObject -Class Win32_Processor -ComputerName . | Select-Object -Property Name
$cpuusage = Get-WmiObject -Class Win32_Processor | Measure-Object -property LoadPercentage -Average | Select Average
$motherboard = Get-WmiObject -Class Win32_BaseBoard -ComputerName .
$gpu = Get-WmiObject -Class Win32_VideoController -ComputerName . | Select-Object -Property Name
$ram = Get-WmiObject -Class Win32_PhysicalMemory -computerName . | Select-Object -Property Capacity, MemoryType
switch ($ram.MemoryType)
{
0 {$ramtype = "Unknown"}
1 {$ramtype = "Other"}
2 {$ramtype = "DRAM"}
3 {$ramtype = "Synchronous DRAM"}
4 {$ramtype = "Cache DRAM"}
5 {$ramtype = "EDO"}
6 {$ramtype = "EDRAM"}
7 {$ramtype = "VRAM"}
8 {$ramtype = "SRAM"}
9 {$ramtype = "RAM"}
10 {$ramtype = "ROM"}
11 {$ramtype = "Flash"}
12 {$ramtype = "EEPROM"}
13 {$ramtype = "FEDROM"}
14 {$ramtype = "EPROM"}
15 {$ramtype = "CDRAM"}
16 {$ramtype = "3DRAM"}
17 {$ramtype = "SDRAM"}
18 {$ramtype = "SGRAM"}
19 {$ramtype = "RDRAM"}
20 {$ramtype = "DDR"}
21 {$ramtype = "DDR2"}
22 {$ramtype = "DDR2 FB-DIMM"}
24 {$ramtype = "DDR3"}
25 {$ramtype = "FBD2"}
default {"Unknown"}
}
$disks = Get-Disks-Infos
$os = Get-WmiObject -Class Win32_OperatingSystem -ComputerName .
Write-Time -msg "Successfully got user infos" -type 1
$actionsuccess++
}
Catch {
Write-Time -msg "Cannot get user infos" -type 3
$actionfail++
}
$actiondone++
### ~~~~~~~~ Network Checking
Write-Time -msg "Trying to read infos of $company in settings.xml..."
## ~~~~~~ We search the differents address regarding the Active Directory Domain the computer is connected to.
Try {
$primaryserver = $xml.Configuration.Custom.PrimaryServer
$DPNetworkports = $xml.Configuration.Ports.DP
$ADnetworkports = $xml.Configuration.Ports.AD
$DPNetworktxml = $xml.Configuration.Custom.DPNetwork.ChildNodes
if ($primaryserver -eq $null -and $DPNetworktxml -eq $null) {
Write-Time -msg "Error : the company $company was not found in the xml file, or its informations are empty." -type 3
Throw 'lol'
}
Write-Time -msg "Successfully got informations for settings.xml" -type 1
$actionsuccess++
}
Catch {
Write-Time -msg "Cannot read required informations in settings.xml. Follow the README to fix it" -type 3
$actionfail++
}
$actiondone++
## ~~~~~~ Primary Servers Network Prerequisites
$actionpsn = 0
$actionpsnyes = 0
$actionpsnno = 0
if ($primaryserver -ne "") {
$primaryservertest = Test-UrlResolution( $primaryserver )
if ($primaryservertest.DnsResolution) {
$actionsuccess++
$actionpsnyes++
}
else {
$actionfail++
$actionpsnno++
}
}
else {
Write-Time -msg "No Primary Server IP found to test..." -type 2
$actionfail++
$actionpsnno++
}
$actiondone++
$actionpsn++
## ~~~~~~ DP Network Prerequisites
$actiondpn = 0
$actiondpnyes = 0
$actiondpnno = 0
$actionadn = 0
$actionadnyes = 0
$actionadnno = 0
# We create a list to store the result of the tests
$globalresults = @()
Foreach ($DPUrl in $DPNetworktxml) {
$globalresults += $false
}
$separator = ","
# We will test for each DP Url registered in the xml file under the company input
$range = 0
Foreach ($DPUrl in $DPNetworktxml) {
$dpnurls = $null
$locallistres = @($false, $false; $false)
# We create another list to store the DP Network URL results
$dpnurllocalarray = @()
[System.Collections.ArrayList]$dpnurlres = $dpnurllocalarray
# If there is an URL written in the settings.xml file, we test the url resolution.
if ($DPUrl.URL -ne "") {
$dpnetworktest = Test-UrlResolution( $DPUrl.URL )
$dpnurlres += $dpnetworktest
if ($dpnetworktest.DnsResolution) {
$actionsuccess++
$actiondpnyes++
}
else {
$actionfail++
$actiondpnno++
}
$actiondone++
$actiondpn++
}
else {
Write-Time -msg "No DP Urls found to test..." -type 2
$actionfail++
$actiondpnno++
$actiondone++
$actiondpn++
}
$locallistres[0] = $dpnurlres
# We manage the DP Network checking for each DP Network URL
# First, we create a new list to register all the dpnvips test results
$dpnviparray = @()
[System.Collections.ArrayList]$dpnvips = $dpnviparray
# We make sure that the sentences in the xml file are correct by deleting any blank character
$separator = ","
$dpnetworkports = ($dpnetworkports -replace '\s','') -split $separator, 0, "simplematch"
$DPIPs = ($DPUrl.DPIPs -replace '\s','') -split $separator, 0, "simplematch"
# If there is at least a DPIP
if ($DPIPs -ne "") {
# We test for each DPIP all the DP ports registered in the xml file.
Foreach ($dpnvip in $DPIPs) {
Foreach ($dpnport in $dpnetworkports) {
Write-Time -msg "Testing $dpnvip on port $dpnport with protocol TCP..."
$localres = Test-VipPorts -Vips $dpnvip -Port $dpnport -Protocol "TCP"
$dpnvips += $localres
if ($localres.GetResponce) {
$actionsuccess++
$actiondpnyes++
}
else {
$actionfail++
$actiondpnno++
}
$actiondone++
$actiondpn++
}
}
$locallistres[1] = $dpnvips
}
else {
Write-Time -msg "No DP IPs found to test..." -type 2
$actionfail++
$actiondpnno++
$actiondone++
$actiondpn++
}
# Active Directory Network Prerequisites
# We create a list to store the results of the Active Directory IPs tests
$ADnetworkiptest = @()
[System.Collections.ArrayList]$ADnetworkiptestlist = $ADnetworkiptest
# We make sure that the sentences in the xml file are correct by deleting any blank character
$separator = ","
$ADnetworkports = ($ADnetworkports -replace '\s','') -split $separator, 0, "simplematch"
$ADIPs = ($DPUrl.ADIPs -replace '\s','') -split $separator, 0, "simplematch"
# If there is at least an Active Directory IP
if ($ADIPs -ne "") {
# We test each Active Directory IP with each ports registered in the xml file.
Foreach ($ADnetworkvip in $ADIPs) {
Foreach ($ADPort in $ADnetworkports ) {
if ($ADPort -eq "389") {
Write-Time -msg "Testing $ADnetworkvip on port $ADPort with protocol TCP..."
$localres = Test-VipPorts -Vips $ADnetworkvip -Port $ADPort -Protocol "TCP"
$ADnetworkiptestlist += $localres
if ($localres.GetResponce -and $localres.Protocol -eq "TCP") {
$actionsuccess++
$actionadnyes++
}
else {
$actionfail++
$actionadnno++
}
$actiondone++
$actionadn++
Write-Time -msg "Testing $ADnetworkvip on port $ADPort with protocol UDP..."
$localres = Test-VipPorts -Vips $ADnetworkvip -Port $ADPort -Protocol "UDP"
$ADnetworkiptestlist += $localres
if ($localres.GetResponce -and $localres.Protocol -eq "TCP") {
$actionsuccess++
$actionadnyes++
}
else {
$actionfail++
$actionadnno++
}
$actiondone++
$actionadn++
}
else {
Write-Time -msg "Testing $ADnetworkvip on port $ADPort with protocol TCP..."
$localres = Test-VipPorts -Vips $ADnetworkvip -Port $ADPort -Protocol "TCP"
$ADnetworkiptestlist += $localres
if ($localres.GetResponce -and $localres.Protocol -eq "TCP") {
$actionsuccess++
$actionadnyes++
}
else {
$actionfail++
$actionadnno++
}
$actiondone++
$actionadn++
}
}
}
$locallistres[2] = $ADnetworkiptestlist
}
else {
Write-Time -msg "No Active Directory IPs found to test..." -type 2
$actionfail++
$actionadnno++
$actiondone++
$actionadn++
}
$dpnurls += $locallistres
$globalresults[$range] = $dpnurls
$range++
}
### ~~~~~~~~ We calculate the porcentage of success of the whole checking process
if ($actiondone -ne 0) {
$success = [math]::Round(( ($actionsuccess/$actiondone) * 100),2)
$successmsg = "<p class='text-danger'>Unknown</p>"
If ($success -gt 75)
{
Write-Time -msg "$success% of success ($actionsuccess/$actiondone)" -type 1
$successmsg = '<p class="text-success">' + $success + '% of success (' + $actionsuccess + '/' + $actiondone +')</p>'
}
Else
{
If ($success -le 75 -and $success -gt 50)
{
Write-Time -msg "Warning : only $success% of success ($actionsuccess/$actiondone)" -type 2
$successmsg = '<p class="text-warning">Warning : ' + $success + '% of success (' + $actionsuccess + '/' + $actiondone +')</p>'
}
Else
{
Write-Time -msg "WARNING : ONLY $success% OF SUCCESS ($actionsuccess/$actiondone) | This computer cannot handle a safe SCCM setup for now." -type 3
$successmsg = '<p class="text-danger">WARNING : ' + $success + '% OF SUCCESS (' + $actionsuccess + '/' + $actiondone +') : This computer cannot handle a safe SCCM setup for now.</p>'
}
}
}
else {
Write-Time -msg "WARNING : ONLY 0% OF SUCCESS (0/0) | This computer cannot handle a safe SCCM setup for now." -type 3
$successmsg = '<p class="text-danger">WARNING : 0% OF SUCCESS (0/0) : This computer cannot handle a safe SCCM setup for now.</p>'
}
## ~~~~~~ We calculate the primary network test sequence porcentage of success
if ($actionpsn -ne 0) {
$successpsn = [math]::Round(( ($actionpsnyes/$actionpsn) * 100),2)
If ($successpsn -gt 75)
{
$successpsnmsg = '<p class="text-success">' + $successpsn + '% of success (' + $actionpsnyes + '/' + $actionpsn +')</p>'
}
Else
{
If ($successpsn -le 75 -and $successpsn -gt 50)
{
$successpsnmsg = '<p class="text-warning">' + $successpsn + '% of success (' + $actionpsnyes + '/' + $actionpsn +')</p>'
}
Else
{
$successpsnmsg = '<p class="text-danger">' + $successpsn + '% of success (' + $actionpsnyes + '/' + $actionpsn +')</p>'
}
}
}
else {
$successpsnnmsg = '<p class="text-danger">0% of success (' + $actionpsnyes + '/' + $actionpsn +')</p>'
}
## ~~~~~~ We calculate the DP Network test sequence porcentage of success
if ($actiondpn -ne 0) {
$successdpn = [math]::Round(( ($actiondpnyes/$actiondpn) * 100),2)
If ($successdpn -gt 75)
{
$successdpnmsg = '<p class="text-success">' + $successdpn + '% of success (' + $actiondpnyes + '/' + $actiondpn +')</p>'
}
Else
{
If ($successdpn -le 75 -and $successdpn -gt 50)
{
$successdpnmsg = '<p class="text-warning">' + $successdpn + '% of success (' + $actiondpnyes + '/' + $actiondpn +')</p>'
}
Else
{
$successdpnnmsg = '<p class="text-danger">' + $successdpn + '% of success (' + $actiondpnyes + '/' + $actiondpn +')</p>'
}
}
}
else {
$successdpnnmsg = '<p class="text-danger">0% of success (' + $actiondpnyes + '/' + $actiondpn +')</p>'
}
## ~~~~~~ We calculate the Active Directory Network test sequence porcentage of success
if ($actionadn -ne 0) {
$successadn = [math]::Round(( ($actionadnyes/$actionadn) * 100),2)
If ($successadn -gt 75)
{
$successadnmsg = '<p class="text-success">' + $successadn + '% of success (' + $actionadnyes + '/' + $actionadn +')</p>'
}
Else
{
If ($successadn -le 75 -and $successadn -gt 50)
{
$successadnmsg = '<p class="text-warning">' + $successadn + '% of success (' + $actionadnyes + '/' + $actionadn +')</p>'
}
Else
{
$successadnmsg = '<p class="text-danger">' + $successadn + '% of success (' + $actionadnyes + '/' + $actionadn +')</p>'
}
}
}
else {
$successadnnmsg = '<p class="text-danger">0% of success (' + $actionadnyes + '/' + $actionadn +')</p>'
}
$endtime = Get-Date
$duration = $endtime - $begintime
#This is responsible for handling HTML/CSS display at then end
$text =
'
<style>
body, html {
width : 100%;
margin : 0px;
background-color: #d9e4ec;
}
p, a, li, ul, h1, h2, h3, h4, h5, table {
font-family: "Hind", sans-serif;
margin : 0px;
}
.text-danger {
color : red;
}
.text-warning {
color : orange;
}
.text-success {
color : green;
}
.logo {
margin-left : 10%;
margin-top : 10px;
}
.title {
width : 100%;
border-bottom : 2px solid rgba(0,0,0,0.3);
}
.report-info {
width : 80%;
margin : auto;
margin-top : 15px;
}
.report-info .content .date {
font-size : 1.4vh;
margin-top : 10px;
}
.duration {
font-size : 1.4vh;
color : #888;
}
.no-central-server {
margin-top : 70px;
color : red;
text-align :center;
font-size : 24px;
}
.si-internet {
color : green;
}
.flex-line-little {
display : flex;
justify-content : space-between;
}
.flex-line {
display : flex;
justify-content : space-between;
width : 80%;
margin : auto;
margin-top : 15px;
}
.flex-line-between {
display : flex;
justify-content : space-between;
margin-top : 15px;
}
.item-little {
width : 150px;
height : 200px;
text-align : center;
color : white;
}
.item-little h2 {
font-family : 32px;
}
.item-little p {
margin-top : 25px;
}
.flex-line .server-config {
display : block;
width : 45%;
background-color : #2a6496;
color : white;
padding : 15px;
}
.flex-line .server-config .sub-title {
margin : 2%;
}
.flex-line .server-services {
display : block;
width : 45%;
background-color : #5F9EA0;
color : white;
padding : 15px;
}
.flex-line .server-services .sub-title {
margin : 2%;
}
.server-config .content, .server-services .content {
font-size : 2vh;
}
.server-config .content b {
text-transform: uppercase;
display:inline-block
}
.server-services .content b {
text-transform: uppercase;
display:inline-block
}
.network-test {
width : 80%;
margin : auto;
margin-top : 25px;
}
.network-item {
width : 90%;
margin : auto;
margin-top : 20px;
}
.network-item h3 {
border-left : 25px solid #2a6496;
font-size : 20px;
padding-left : 15px;
}
.network-item table {
margin-top : 25px;
margin-bottom : 25px;
width : 100%;
background-color : white;
border-radius : 6px;
border : 1px solid ccc;
border-collapse: collapse;
box-shadow : 1px 1px 0px #888;
}
.network-item table th {
font-weight : bold;
}
.network-item table th, .network-item table td {
width : auto;
padding : 10px;
padding-left : 20px;
border-bottom : 1px solid #ccc;
}
</style>
<html>
<head>
<title>SCCM Check Prerequisites v2.0 | ' + $date + '</title>
<link href="RESSOURCES\favicon.ico" rel="icon" type="image/vnd.microsoft.icon">
<link href="https://fonts.googleapis.com/css?family=Hind" rel="stylesheet">
<meta charset="UTF-8">
</head>
<body>
<div class="logo">
<img src="your-logo-url" alt="your-logo-description">
</div>
<div class="report-info">
<h2 class="title">Report Info</h2>
<div class="content">
<div class="flex-line-little"><div class="date"><p>' + $date + '</p></div> <div class="porcentage-success">' + $successmsg + '</div> </div>
<div class="flex-line-little">
<div class="server">
<p>Request from <b>' + $servername + '</b> owned by <b>' + $company + '</b>.</p></div>
<p class="duration">Checking done in ' + $duration + '</p>
</div>
</div>
</div>
<!--<div class="service-list">
<h2 class="title">Service List</h2>
<div class="content">