-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOSD-BIOSPrerequisitesTool.ps1
2264 lines (2027 loc) · 198 KB
/
OSD-BIOSPrerequisitesTool.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
#========================================================================
#
# Created: 2016-04-22
# Author: Richard tracy
# Idea From: Nickolaj Andersen
#
#========================================================================
[void][Reflection.Assembly]::LoadWithPartialName("System.Security")
## Variables: Script Name and Script Paths
[string]$scriptPath = $MyInvocation.MyCommand.Definition
[string]$scriptName = [IO.Path]::GetFileNameWithoutExtension($scriptPath)
[string]$scriptFileName = Split-Path -Path $scriptPath -Leaf
[string]$scriptRoot = Split-Path -Path $scriptPath -Parent
[string]$invokingScript = (Get-Variable -Name 'MyInvocation').Value.ScriptName
#include additional extensions
If (Test-Path -Path ($scriptRoot + '.\PowershellModules\functions.ps1')){
. ($scriptRoot + '.\PowershellModules\functions.ps1')
}
# Get the invoking script directory
If ($invokingScript) {
# If this script was invoked by another script
[string]$scriptParentPath = Split-Path -Path $invokingScript -Parent
}
Else {
# If this script was not invoked by another script, fall back to the directory one level above this script
[string]$scriptParentPath = (Get-Item -LiteralPath $scriptRoot).Parent.FullName
}
##*=============================================
##* READ CONFIG.XML FILE
##*=============================================
[string]$ConfigFile = Join-Path -Path $scriptRoot -ChildPath 'OSD-BIOSConfig.xml'
[xml]$XmlConfigFile = Get-Content $ConfigFile
$UseRemoteInstead = $XmlConfigFile.app.configs.useRemote.remote
If ($UseRemoteInstead -eq $true){
$remoteConfig = $XmlConfigFile.app.configs.useRemote.path
If (Test-Path $remoteConfig){
[xml]$XmlConfigFile = Get-Content $remoteConfig
}
}
$apptitle = $XmlConfigFile.app.title
$appversion = $XmlConfigFile.app.version
$TabPageConfigs = $XmlConfigFile.app.configs.pagetabs.tab
$SupportedOperatingSystems = $XmlConfigFile.app.supported.OSbuilds.OS
$MinimumOS = $SupportedOperatingSystems | Where-Object id -eq "minimum"
[int]$MinimumOSversion = $MinimumOS.version
$SupportedSystems = $XmlConfigFile.app.supported.hardwarePlatforms.system
$SupportedManufacturers = $SupportedSystems.manufacturer | sort -Unique
$SupportedModels = $SupportedSystems.model
[Xml.XmlElement]$XMLAdditionalProviders = $XmlConfigFile.app.configs.additionalProviders
[array]$DellProviders = $XMLAdditionalProviders.provider | Where-Object {$_.platformsupport -eq "Dell Inc."}
Foreach ($provider in $DellProviders){
#write-host $provider.name
#write-host $provider.enabled
If ($provider.name -eq "Dell Command | Configure Toolkit"){
If ($provider.enabled -eq "true") {
$UseDellCCTK = $true
}Else {
$UseDellCCTK = $false
}
[string]$DellCCTKPath = $provider.path_x64
[string]$DellCCTKPathx86 = $provider.path_x86
}
If ($provider.name -eq "DellBIOSPowershell"){
If ($provider.enabled -eq "true") {
$UseDellPSProvider = $true
}Else {
$UseDellPSProvider = $false
}
[string]$DellPSProviderPath = $provider.path_x64
[string]$DellPSProviderPathX86 = $provider.path_x86
}
}
#[array]$BIOSKnownUsedpwd = @($XmlConfigFile.app.configs.knownBIOSPasswords.password)
[array]$BIOSKnownUsedpwd = @($XmlConfigFile.app.configs.knownBIOSPasswords.cryptpassword)
#to encrypt load Encrypt-String and then run it, copy the results in config file
#Encrypt-String -String <password> -Passphrase "<Passphrase>"
If ($XmlConfigFile.app.configs.debugmode -eq 'true'){
[Boolean]$Global:LogDebugMode = $True
} Else {
[Boolean]$Global:LogDebugMode = $False
}
If ($XmlConfigFile.app.configs.alwaysCheckBIOS -eq 'true'){
[Boolean]$Global:IgnorePrereqs = $true
} Else {
[Boolean]$Global:IgnorePrereqs = $false
}
##*=============================================
##* VARIABLE DECLARATION
##*=============================================
$Global:SMCSharedData = 0
$ComputerName = $env:COMPUTERNAME
$ComputerSystem = Get-WmiObject -Namespace "root\cimv2" -Class Win32_ComputerSystem
[string]$Manufacturer = $ComputerSystem.Manufacturer
[string]$Model = $ComputerSystem.Model
[int]$OSProductType = Get-WmiObject -Namespace "root\cimv2" -Class Win32_OperatingSystem | Select-Object -ExpandProperty ProductType
[string]$OSCaption = Get-WmiObject -Namespace "root\cimv2" -Class Win32_OperatingSystem | Select-Object -ExpandProperty Caption
[int]$OSMajor = ([System.Environment]::OSVersion.Version).Major
[int]$OSBuildNumber = ([System.Environment]::OSVersion.Version).Build
[boolean]$Is64Bit = [boolean]((Get-WmiObject -Class 'Win32_Processor' | Where-Object { $_.DeviceID -eq 'CPU0' } | Select-Object -ExpandProperty 'AddressWidth') -eq 64)
If ($Is64Bit) { [string]$envOSArchitecture = '64-bit' } Else { [string]$envOSArchitecture = '32-bit' }
##*=============================================
##* FUNCTIONS
##*=============================================
function Load-Form {
$Form.Controls.Add($TabControl)
$TabControl.Controls.AddRange(@(
$TabSHBPage,
$TabLoggingPage
))
$TabSHBPage.Controls.AddRange(@(
$ProgressBar,
$LabelHeader,
$LabelSupportedModel,
$LabelSupportedOS,
#$LabelPowerShell,
$LabelUEFI,
$OutputBoxSysInfo,
$LabelBIOSRevision,
$LabelBIOSPassword,
$LabelBIOSTPM,
$LabelBIOSTPMEnabled,
$LabelBIOSTPMActive,
$LabelBIOSVT,
$LabelBIOSVTTE,
$LabelBIOSVTDirectIO,
$LabelLegacyROM,
$LabelSecureBoot,
#$PBReboot,
$PBModel,
$PBOS,
#$PBPS,
$PBUEFI,
#$GBReboot,
$GBModel,
$GBOS,
#$GBPS,
$GBUEFI,
$PBBIOSRevision,
$PBBIOSPassword,
$PBBIOSTPM,
$PBBIOSTPMON,
$PBBIOSTPMACT,
$PBBIOSVT,
$PBBIOSVTDirectIO,
$PBBIOSVTTE,
$PBLEGACYOROM,
$PBSECUREBOOT,
$LBOSVersions,
$GBOSVersion,
$GBSystemModel,
$GBBIOSRevision,
$GBBIOSPassword,
$GBBIOSTPM,
$GBBIOSTPMON,
$GBBIOSTPMACT,
$GBBIOSVT,
$GBBIOSVTDirectIO,
$GBBIOSVTTE,
$GBLEGACYROM,
$GBSECUREBOOT,
$GBBIOSInfo,
$GBTPMSettings,
$GBVTSettings,
$GBBootSettings,
$CBPrerequisitesOverride,
$GBSystemValidation,
#$CBContinueOverride,
$ButtonContinueExit
))
$Form.Add_Shown({Retrieve-SystemInfo -DisplayType "Basic" -DisplayOutbox -IgnorePing})
$Form.Add_Shown({Validate-RunChecks})
$Form.Add_Shown({Validate-BIOSChecks})
$Form.Add_Shown({$Form.Activate()})
[void]$Form.ShowDialog()
}
function Load-LoggingPage {
if (-not(($TabLoggingPage.Controls | Measure-Object).Count -ge 1)) {
$TabLoggingPage.Controls.Clear()
$TabLoggingPage.Controls.AddRange(@(
$OutputBoxLogging,
$ButtonExportLogging
))
}
if ($ButtonExportLogging.Enabled -eq $false) {
$ButtonExportLogging.Enabled = $true
}
}
function Interactive-TabPages {
param(
[parameter(Mandatory=$true)]
[ValidateSet("Enable","Disable")]
$Mode
)
Begin {
$CurrentTabPage = $TabControl.SelectedTab.Name
switch ($Mode) {
"Enable" { $TabPageMode = $true }
"Disable" { $TabPageMode = $false }
}
$TabNameArrayList = New-Object -TypeName System.Collections.ArrayList
foreach ($TabNameArrayListObject in (($TabControl.TabPages.Name))) {
$TabNameArrayList.Add($TabNameArrayListObject)
}
}
Process {
foreach ($TabPageObject in $TabNameArrayList) {
if ($Mode -like "Disable") {
if ($CurrentTabPage -like "SHB") {
$TabLoggingPage.Enabled = $TabPageMode
}
}
else {
$TabSHBPage.Enabled = $TabPageMode
$TabLoggingPage.Enabled = $TabPageMode
}
}
}
}
function Interactive-Buttons {
param(
[parameter(Mandatory=$true)]
[ValidateSet("Enable","Disable")]
$Mode,
[parameter(Mandatory=$true)]
[ValidateSet("Prerequisites","Validation")]
$Module
)
Begin {
switch ($Mode) {
"Enable" { $TabPageButtonMode = $true }
"Disable" { $TabPageButtonMode = $false }
}
}
Process {
if ($Module -eq "Validation") {
foreach ($Control in $TabPageSiteRoles.Controls) {
if ($Control.GetType().ToString() -eq "System.Windows.Forms.ComboBox") {
$Control.Enabled = $TabPageButtonMode
}
}
}
if ($Module -eq "Prerequisites") {
foreach ($Control in $TabPageOther.Controls) {
if ($Control.GetType().ToString() -eq "System.Windows.Forms.CheckBox") {
$Control.Enabled = $TabPageRadioButtonMode
}
}
}
}
}
function Validate-RunChecks {
$ValidateCounter = 0
<#if (Validate-PendingReboot) {
$ValidateCounter++
}#>
if (Validate-System) {
$ValidateCounter++
}
if (Validate-OSBuild) {
$ValidateCounter++
}
<#if (Validate-PowerShellVer) {
$ValidateCounter++
}
if (Validate-Elevated) {
$ValidateCounter++
}#>
if (Validate-UEFICheck) {
$ValidateCounter++
}
if ($ValidateCounter -ge 3) {
Interactive-TabPages -Mode Enable
Write-OutputBox -OutputBoxMessage "All validation checks passed successfully" -Type "INFO: " -Object Logging
$CBPrerequisitesOverride.Enabled = $false
}
else {
Interactive-TabPages -Mode Disable
Write-OutputBox -OutputBoxMessage "All validation checks did not pass successfully, remediate the errors and re-launch the tool or check the override checkbox to use the tool anyway" -Type "ERROR: " -Object Logging
}
If ($IgnorePrereqs){
return $global:PreValidation = $true
} Else {
return $global:PreValidation = $ValidateCounter
}
}
function Validate-BIOSChecks {
$ProgressBar.Value = 0
$ProgressBar.Maximum = 11
$ValidateCounter = 0
$ProgressBar.PerformStep()
if (Load-SystemProvider) {
$ValidateCounter++
}
$ProgressBar.PerformStep()
if (Validate-BIOSRevision) {
$ValidateCounter++
}
$ProgressBar.PerformStep()
if (Validate-BIOSPassword) {
$ValidateCounter++
}
$ProgressBar.PerformStep()
if (Validate-LegacyROM) {
$ValidateCounter++
}
$ProgressBar.PerformStep()
if (Validate-SecureBoot) {
$ValidateCounter++
}
$ProgressBar.PerformStep()
if (Validate-TPMModule) {
$ValidateCounter++
}
$ProgressBar.PerformStep()
if (Validate-TPMEnabled) {
$ValidateCounter++
}
$ProgressBar.PerformStep()
if (Validate-TPMActivated) {
$ValidateCounter++
}
$ProgressBar.PerformStep()
if (Validate-VTFeature) {
$ValidateCounter++
}
$ProgressBar.PerformStep()
if (Validate-VTDirectIO) {
$ValidateCounter++
}
$ProgressBar.PerformStep()
if (Validate-VTTrustedExecution) {
$ValidateCounter++
}
if ($ValidateCounter -ge 11) {
#Interactive-TabPages -Mode Enable
Write-OutputBox -OutputBoxMessage "BIOS checks passed successfully" -Type "INFO: " -Object Logging
$CBContinueOverride.Enabled = $false
}
else {
#Interactive-TabPages -Mode Disable
Write-OutputBox -OutputBoxMessage "BIOS checks did not pass successfully, system may not be compatible for Secure Host Baseline." -Type "ERROR: " -Object Logging
}
}
Function Retrieve-SystemInfo
<#
.SYNOPSIS
Get Complete details of any server Local or remote
.DESCRIPTION
This function uses WMI class to connect to remote machine and get all related details
.PARAMETER COMPUTERNAMES
Just Pass computer name as Its parameter
.EXAMPLE
Retrieve-SystemInfo
.EXAMPLE
Retrieve-SystemInfo -ComputerName HQSPDBSP01
.NOTES
To get help:
Get-Help Retrieve-SystemInfo
.LINK
http://sqlpowershell.wordpress.com
#>
{
param(
[ValidateSet("Detail","Basic","NetInfo")]
[string]$DisplayType = "Detail",
[switch] $DisplayForm = $false,
[switch] $DisplayOutbox = $false,
[switch] $IgnorePing
)
# Declare main data hash to be populated later
$data = @{}
$data.' Computer Name:' = $env:ComputerName
If($DisplayType -eq "Detail"){
# Do a DNS lookup with a .NET class method. Suppress error messages.
$ErrorActionPreference = 'SilentlyContinue'
if ( $ips = [System.Net.Dns]::GetHostAddresses($env:ComputerName) | foreach { $_.IPAddressToString } ) {
$data.'IP Address(es) from DNS' = ($ips -join ', ')
}
else {
$data.'IP Address from DNS' = 'Could not resolve'
}
# Make errors visible again
$ErrorActionPreference = 'Continue'
# We'll assume no ping reply means it's dead. Try this anyway if -IgnorePing is specified
if ($ping -or $ignorePing) {
$data.'WMI Data Collection Attempt' = 'Yes (ping reply or -IgnorePing)'
# Get various info from the ComputerSystem WMI class
if ($wmi = Get-WmiObject -Class Win32_ComputerSystem -ErrorAction SilentlyContinue) {
$data.'Computer Hardware Manufacturer' = $wmi.Manufacturer
$data.'Computer Hardware Model' = $wmi.Model
$data.'Memory Physical in MB' = ($wmi.TotalPhysicalMemory/1MB).ToString('N')
$data.'Logged On User' = $wmi.Username
}
$wmi = $null
# Get the free/total disk space from local disks (DriveType 3)
if ($wmi = Get-WmiObject -Class Win32_LogicalDisk -Filter 'DriveType=3' -ErrorAction SilentlyContinue) {
$wmi | Select 'DeviceID', 'Size', 'FreeSpace' | Foreach {
$data."Local disk $($_.DeviceID)" = ('' + ($_.FreeSpace/1MB).ToString('N') + ' MB free of ' + ($_.Size/1MB).ToString('N') + ' MB total space with ' + ($_.Size/1MB - $_.FreeSpace/1MB).ToString('N') +' MB Used Space')
}
}
$wmi = $null
# Get IP addresses from all local network adapters through WMI
if ($wmi = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ErrorAction SilentlyContinue) {
$Ips = @{}
$wmi | Where { $_.IPAddress -match '\S+' } | Foreach { $Ips.$($_.IPAddress -join ', ') = $_.MACAddress }
$counter = 0
$Ips.GetEnumerator() | Foreach {
$counter++; $data."IP Address $counter" = '' + $_.Name + ' (MAC: ' + $_.Value + ')'
}
}
$wmi = $null
# Get CPU information with WMI
if ($wmi = Get-WmiObject -Class Win32_Processor -ErrorAction SilentlyContinue) {
$wmi | Foreach {
$maxClockSpeed = $_.MaxClockSpeed
$numberOfCores += $_.NumberOfCores
$description = $_.Description
$numberOfLogProc += $_.NumberOfLogicalProcessors
$socketDesignation = $_.SocketDesignation
$status = $_.Status
$manufacturer = $_.Manufacturer
$name = $_.Name
}
$data.'CPU Clock Speed' = $maxClockSpeed
$data.'CPU Cores' = $numberOfCores
$data.'CPU Description' = $description
$data.'CPU Logical Processors' = $numberOfLogProc
$data.'CPU Socket' = $socketDesignation
$data.'CPU Status' = $status
$data.'CPU Manufacturer' = $manufacturer
$data.'CPU Name' = $name -replace '\s+', ' '
}
$wmi = $null
# Get BIOS info from WMI
if ($wmi = Get-WmiObject -Class Win32_Bios -ErrorAction SilentlyContinue) {
$data.'BIOS Manufacturer' = $wmi.Manufacturer
$data.'BIOS Name' = $wmi.Name
$data.'BIOS Version' = $wmi.Version
$data.'BIOS SM Version:' = $wmi.SMBIOSBIOSVersion
}
$wmi = $null
# Get operating system info from WMI
if ($wmi = Get-WmiObject -Class Win32_OperatingSystem -ErrorAction SilentlyContinue) {
$data.'OS Boot Time' = $wmi.ConvertToDateTime($wmi.LastBootUpTime)
$data.'OS System Drive' = $wmi.SystemDrive
$data.'OS System Device' = $wmi.SystemDevice
$data.'OS Language ' = $wmi.OSLanguage
$data.'OS Version' = $wmi.Version
$data.'OS Windows dir' = $wmi.WindowsDirectory
$data.'OS Name' = $wmi.Caption
$data.'OS Install Date' = $wmi.ConvertToDateTime($wmi.InstallDate)
$data.'OS Service Pack' = [string]$wmi.ServicePackMajorVersion + '.' + $wmi.ServicePackMinorVersion
}
# Scan for open ports
$ports = @{
'File shares/RPC' = '139' ;
'File shares' = '445' ;
'RDP' = '3389';
#'Zenworks' = '1761';
}
foreach ($service in $ports.Keys) {
$socket = New-Object Net.Sockets.TcpClient
# Suppress error messages
$ErrorActionPreference = 'SilentlyContinue'
# Try to connect
$socket.Connect($env:ComputerName, $ports.$service)
# Make error messages visible again
$ErrorActionPreference = 'Continue'
if ($socket.Connected) {
$data."Port $($ports.$service) ($service)" = 'Open'
$socket.Close()
}
else {
$data."Port $($ports.$service) ($service)" = 'Closed or filtered'
}
$socket = $null
}
}
else {
$data.'WMI Data Collected' = 'No (no ping reply and -IgnorePing not specified)'
}
$wmi = $null
if ($wmi = Get-WmiObject -Class Win32_OperatingSystem -ErrorAction SilentlyContinue| Select-Object Name, TotalVisibleMemorySize, FreePhysicalMemory,TotalVirtualMemorySize,FreeVirtualMemory,FreeSpaceInPagingFiles,NumberofProcesses,NumberOfUsers ) {
$wmi | Foreach {
$TotalRAM = $_.TotalVisibleMemorySize/1MB
$FreeRAM = $_.FreePhysicalMemory/1MB
$UsedRAM = $_.TotalVisibleMemorySize/1MB - $_.FreePhysicalMemory/1MB
$TotalRAM = [Math]::Round($TotalRAM, 2)
$FreeRAM = [Math]::Round($FreeRAM, 2)
$UsedRAM = [Math]::Round($UsedRAM, 2)
$RAMPercentFree = ($FreeRAM / $TotalRAM) * 100
$RAMPercentFree = [Math]::Round($RAMPercentFree, 2)
$TotalVirtualMemorySize = [Math]::Round($_.TotalVirtualMemorySize/1MB, 3)
$FreeVirtualMemory = [Math]::Round($_.FreeVirtualMemory/1MB, 3)
$FreeSpaceInPagingFiles = [Math]::Round($_.FreeSpaceInPagingFiles/1MB, 3)
$NumberofProcesses = $_.NumberofProcesses
$NumberOfUsers = $_.NumberOfUsers
}
$data.'Memory - Total RAM GB ' = $TotalRAM
$data.'Memory - RAM Free GB' = $FreeRAM
$data.'Memory - RAM Used GB' = $UsedRAM
$data.'Memory - Percentage Free'= $RAMPercentFree
$data.'Memory - TotalVirtualMemorySize' = $TotalVirtualMemorySize
$data.'Memory - FreeVirtualMemory' = $FreeVirtualMemory
$data.'Memory - FreeSpaceInPagingFiles' = $FreeSpaceInPagingFiles
$data.'NumberofProcesses'= $NumberofProcesses
$data.'NumberOfUsers' = $NumberOfUsers -replace '\s+', ' '
}
# Output data
"#"*80
"OS Complete Information"
"Generated $(get-date)"
"Generated from $(gc env:computername)"
"#"*80
} ElseIf ($DisplayType -eq "NetInfo"){
} Else {
# Get operating system info from WMI
if ($wmi = Get-WmiObject -Class Win32_OperatingSystem -ErrorAction SilentlyContinue) {
If(!$wmi.Caption){$Caption="WinPE"; $Name = "PE:"}Else{$Caption=$wmi.Caption; $Name = "OS:"}
$data." $Name" = "$Caption ("+$wmi.Version+")"
}
# Get BIOS info from WMI
if ($wmi = Get-WmiObject -Class Win32_Bios -ErrorAction SilentlyContinue) {
$data.'BIOS Version:' = $wmi.SMBIOSBIOSVersion
}
$wmi = $null
if ($wmi = Get-WmiObject -Class Win32_ComputerSystem -ErrorAction SilentlyContinue) {
$data.'Manufacturer:' = $wmi.Manufacturer
$data.'Model:' = $wmi.Model
}
$wmi = $null
# Get IP addresses from all local network adapters through WMI
if ($wmi = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ErrorAction SilentlyContinue) {
$Ips = @{}
$wmi | Where { $_.IPAddress -match '\S+' } | Foreach { $Ips.$($_.IPAddress -join ', ' ) = $_.MACAddress }
$counter = 0
$Ips.GetEnumerator() | Foreach {
$counter++; $data.("Net Address["+$counter+"]:") = '' + $_.Name + ' MAC['+$counter+']:' + $_.Value + ''
}
}
$wmi = $null
}
$EnumeratedData = [system.String]::Join("`n", ($data.GetEnumerator()| Sort-Object 'Name' | Format-Table -HideTableHeaders -AutoSize | out-string))
#$EnumeratedData = ($data.GetEnumerator()| Sort-Object 'Name' | format-table -HideTableHeaders | out-string)
If($DisplayOutbox){
Write-OutputBox -OutputBoxMessage $EnumeratedData -Type " " -Object SysInfo
} Else{
$data.GetEnumerator() | Sort-Object 'Name' | Format-Table -AutoSize
}
If($DisplayForm){$data.GetEnumerator() | Sort-Object 'Name' | Out-GridView -Title "$env:ComputerName Information"}
}
function Load-SystemProvider {
If ($Manufacturer -eq "Dell Inc."){
If ($UseDellCCTK -eq $true){
If ($Is64Bit -and (Test-Path $DellCCTKPath)){
$HAPI = "hapint64.exe"
Write-OutputBox -OutputBoxMessage "Dell Command | Configure Tool Kit loading driver: $HAPI" -Type "INFO: " -Object Logging
}ElseIf(Test-Path $DellCCTKPathX86) {
$HAPI = "hapint.exe"
Write-OutputBox -OutputBoxMessage "Dell Command | Configure Tool Kit loaded driver: $HAPI" -Type "INFO: " -Object Logging
}Else {
Write-OutputBox -OutputBoxMessage "Unable to find Dell Command | Configure Tool Kit HAPI driver" -Type "ERROR: " -Object Logging
}
$private:returnCode = $null
$callexe = New-Object System.Diagnostics.ProcessStartInfo
$callexe.FileName = "$DellCCTKPath\HAPI\$HAPI"
$callexe.RedirectStandardError = $true
$callexe.RedirectStandardOutput = $true
$callexe.UseShellExecute = $false
$callexe.Arguments = "-i -k C-C-T-K -p ""$HAPI"" -q"
$callexe.WindowStyle = 'Minimized'
$process = New-Object System.Diagnostics.Process
$process.StartInfo = $callexe
$process.Start() | Out-Null
$process.WaitForExit()
$stdout = $process.StandardOutput.ReadToEnd()
$stderr = $process.StandardError.ReadToEnd()
Write-OutputBox -OutputBoxMessage ("Running: " + $callexe.FileName + " " + $callexe.Arguments) -Type "INFO: " -Object Logging
If ($process.ExitCode -eq 0){
Write-OutputBox -OutputBoxMessage "Successfully installed CCTK HAPI drivers" -Type "INFO: " -Object Logging
}Else{
Write-OutputBox -OutputBoxMessage ("Unable to install the CCTK HAPI drivers with errorcode: " + $process.ExitCode) -Type "ERROR: " -Object Logging
}
}
If ($UseDellPSProvider -eq $true){
If ($Is64Bit -and (Test-Path $DellPSProviderPath)){
Import-Module "$DellPSProviderPath\DellBIOSProvider.PSM1"
Write-OutputBox -OutputBoxMessage "Dell Powershell Provider loaded" -Type "INFO: " -Object Logging
}ElseIf(Test-Path $DellPSProviderPathX86) {
Import-Module "$DellPSProviderPathX86\DellBIOSProvider.PSM1"
Write-OutputBox -OutputBoxMessage "Dell Powershell Provider loaded" -Type "INFO: " -Object Logging
}Else{
Write-OutputBox -OutputBoxMessage "Unable to find Dell Powershell Provider" -Type "ERROR: " -Object Logging
}
}
} ElseIf ($Manufacturer -eq "Hewlett Packard"){
Write-OutputBox -OutputBoxMessage "Unable to load a system Provider, nothing provided" -Type "WARNING: " -Object Logging
} ElseIf ($Manufacturer -eq "System manufacturer"){
Write-OutputBox -OutputBoxMessage "Unable to load a system Provider, nothing provided" -Type "WARNING: " -Object Logging
} Else {
Write-OutputBox -OutputBoxMessage "Unable to load a system Provider, unsupported hardware" -Type "ERROR: " -Object Logging
}
}
Function Execute-DellCCTK{
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true)]
[Alias('Arguments')]
[ValidateNotNullorEmpty()]
[string[]]$Parameters,
[Parameter(Mandatory=$false)]
[ValidateNotNullorEmpty()]
[string]$WorkingDirectory,
[Parameter(Mandatory=$false)]
[switch]$PassThru = $false,
[Parameter(Mandatory=$false)]
[switch]$DebugLog = $Global:LogDebugMode
)
$Path = $false
Begin {
If ($Is64Bit -and (Test-Path $DellCCTKPath)){
$Path = "$DellCCTKPath\cctk.exe"
Write-OutputBox -OutputBoxMessage "Dell Command | Configure Tool Kit loaded: $Path" -Type "INFO: " -Object Logging
}ElseIf(Test-Path $DellCCTKPathX86) {
$Path = "$DellCCTKPathX86\cctk.exe"
Write-OutputBox -OutputBoxMessage "Dell Command | Configure Tool Kit loaded: $Path" -Type "INFO: " -Object Logging
}Else {
Write-OutputBox -OutputBoxMessage "Unable to find Dell Command | Configure Tool Kit" -Type "ERROR: " -Object Logging
}
}
Process {
IF($Path){Return}
Try {
$private:returnCode = $null
## Validate and find the fully qualified path for the $Path variable.
If (([IO.Path]::IsPathRooted($Path)) -and ([IO.Path]::HasExtension($Path))) {
If ($DebugLog){Write-OutputBox -OutputBoxMessage "[$Path] is a valid fully qualified path" -Type "INFO: " -Object Logging}
If (-not (Test-Path -LiteralPath $Path -PathType 'Leaf' -ErrorAction 'Stop')) {
Throw "File [$Path] not found."
}
}
Else {
# The first directory to search will be the 'Files' subdirectory of the script directory
[string]$PathFolders = $Path
# Add the current location of the console (Windows always searches this location first)
[string]$PathFolders = $PathFolders + ';' + (Get-Location -PSProvider 'FileSystem').Path
# Add the new path locations to the PATH environment variable
$env:PATH = $PathFolders + ';' + $env:PATH
# Get the fully qualified path for the file. Get-Command searches PATH environment variable to find this value.
[string]$FullyQualifiedPath = Get-Command -Name $Path -CommandType 'Application' -TotalCount 1 -Syntax -ErrorAction 'Stop'
# Revert the PATH environment variable to it's original value
$env:PATH = $env:PATH -replace [regex]::Escape($PathFolders + ';'), ''
If ($FullyQualifiedPath) {
Write-OutputBox -OutputBoxMessage "[$Path] successfully resolved to fully qualified path [$FullyQualifiedPath]." -Type "INFO: " -Object Logging
$Path = $FullyQualifiedPath
}
Else {
Throw "[$Path] contains an invalid path or file name."
}
}
## Set the Working directory (if not specified)
If (-not $WorkingDirectory) { $WorkingDirectory = Split-Path -Path $Path -Parent -ErrorAction 'Stop' }
Try {
## Disable Zone checking to prevent warnings when running executables
$env:SEE_MASK_NOZONECHECKS = 1
## Define process
$CCTKStartInfo = New-Object -TypeName 'System.Diagnostics.ProcessStartInfo' -ErrorAction 'Stop'
$CCTKStartInfo.FileName = $Path
$CCTKStartInfo.WorkingDirectory = $WorkingDirectory
$CCTKStartInfo.UseShellExecute = $false
$CCTKStartInfo.ErrorDialog = $false
$CCTKStartInfo.RedirectStandardOutput = $true
$CCTKStartInfo.RedirectStandardError = $true
$CCTKStartInfo.CreateNoWindow = $false
If ($Parameters) { $CCTKStartInfo.Arguments = $Parameters }
$CCTKStartInfo.WindowStyle = 'Minimized'
$process = New-Object -TypeName 'System.Diagnostics.Process' -ErrorAction 'Stop'
$process.StartInfo = $CCTKStartInfo
## Add event handler to capture process's standard output redirection
[scriptblock]$processEventHandler = { If (-not [string]::IsNullOrEmpty($EventArgs.Data)) { $Event.MessageData.AppendLine($EventArgs.Data) } }
$stdOutBuilder = New-Object -TypeName 'System.Text.StringBuilder' -ArgumentList ''
$stdOutEvent = Register-ObjectEvent -InputObject $process -Action $processEventHandler -EventName 'OutputDataReceived' -MessageData $stdOutBuilder -ErrorAction 'Stop'
## Start Process
If ($DebugLog){Write-OutputBox -OutputBoxMessage "Working Directory is [$WorkingDirectory]." -Type "INFO: " -Object Logging}
If ($Parameters) {
Write-OutputBox -OutputBoxMessage "Executing [$Path $Parameters]" -Type "INFO: " -Object Logging
} Else {
Write-OutputBox -OutputBoxMessage "Executing [$Path]" -Type "INFO: " -Object Logging
}
[boolean]$processStarted = $process.Start()
$process.BeginOutputReadLine()
$stdErr = $($process.StandardError.ReadToEnd()).ToString() -replace $null,''
## Instructs the Process component to wait indefinitely for the associated process to exit.
$process.WaitForExit()
## HasExited indicates that the associated process has terminated, either normally or abnormally. Wait until HasExited returns $true.
While (-not ($process.HasExited)) { $process.Refresh(); Start-Sleep -Seconds 1 }
## Get the exit code for the process
Try {
[int32]$returnCode = $process.ExitCode
}
Catch [System.Management.Automation.PSInvalidCastException] {
# Catch exit codes that are out of int32 range
[int32]$returnCode = 136
}
## Unregister standard output event to retrieve process output
If ($stdOutEvent) { Unregister-Event -SourceIdentifier $stdOutEvent.Name -ErrorAction 'Stop'; $stdOutEvent = $null }
$stdOut = $stdOutBuilder.ToString() -replace $null,''
If ($stdErr.Length -gt 0) {
If ($DebugLog){Write-OutputBox -OutputBoxMessage "Standard error output from the process: $stdErr" -Type "WARNING: " -Object Logging}
}
}
Finally {
## Make sure the standard output event is unregistered
If ($stdOutEvent) { Unregister-Event -SourceIdentifier $stdOutEvent.Name -ErrorAction 'Stop'}
## Free resources associated with the process, this does not cause process to exit
If ($process) { $process.Close() }
## Re-enable Zone checking
Remove-Item -LiteralPath 'env:SEE_MASK_NOZONECHECKS' -ErrorAction 'SilentlyContinue'
}
## If the passthru switch is specified, return the exit code and any output from process
If ($PassThru) {
If ($DebugLog){Write-OutputBox -OutputBoxMessage "cctk completed with exit code [$returnCode]." -Type "INFO: " -Object Logging}
[psobject]$ExecutionResults = New-Object -TypeName 'PSObject' -Property @{ ExitCode = $returnCode; StdOut = $stdOut; StdErr = $stdErr }
Write-Output -InputObject $ExecutionResults
} Else {
If ($DebugLog){Write-Host "cctk completed with exit code [$returnCode]."}
$returnCode
}
}
Catch {
If ([string]::IsNullOrEmpty([string]$returnCode)) {
[int32]$returnCode = 136
}Else {
If ($DebugLog){Write-OutputBox -OutputBoxMessage "cctk completed with exit code [$returnCode]. Function failed." -Type "ERROR: " -Object Logging}
}
If ($PassThru) {
[psobject]$ExecutionResults = New-Object -TypeName 'PSObject' -Property @{ ExitCode = $returnCode; StdOut = If ($stdOut) { $stdOut } Else { '' }; StdErr = If ($stdErr) { $stdErr } Else { '' } }
Write-Output -InputObject $ExecutionResults
}Else {
If ($DebugLog){Write-Host "cctk completed with exit code [$returnCode]. Function failed."}
$returnCode
}
}
}
}
Function Test-DellCCTK {
[CmdletBinding()]
Param (
[Parameter(Mandatory=$false)]
[Alias('FilePath')]
[ValidateNotNullorEmpty()]
[string]$Path = $CCTK,
[Parameter(Mandatory=$true)]
[Alias('Arguments')]
[ValidateNotNullorEmpty()]
[string[]]$Parameters,
[Parameter(Mandatory=$false)]
[switch]$PassThru = $false
)
$result = Execute-DellCCTK -Parameters "--Asset=TestCCTK" -PassThru
If ($DebugLog){Write-Host "[cctk --Asset=TestCCTK] exitcode: " $result.StdOut}
If ($result.ExitCode -eq 0){
}
Execute-DellCCTK -Parameters ($parameters + " --valsetuppwd=$BIOSpwd") -PassThru
Execute-DellCCTK -Parameters "--setuppwd='' --valsetuppwd=$BIOSpwd"
If ($DebugLog){Write-Host "Cleared BIOS Password"}
}
function Run-DellPSProvider {
cd DellSmbios:
<# Examples
Set-Item Dellsmbios:\PostBehaviour\NumLock Enabled
#Set BIOS Admin Password
Set-Item -Path Dellsmbios\Security\AdminPassword –Value dell123
#Change BIOS Admin Password
Set-Item -Path Dellsmbios\Security\AdminPassword –Value dell1234 –Password dell123
#Clear BIOS Admin Password
Set-Item -Path Dellsmbios\Security\AdminPassword –Value “” –Password dell123
#Disable Chassis Intrusion alert
Set-Item -Path Dellsmbios\Security\ChassisIntrusion -Value Disabled
#Set Wake On Lancd
Set-Item -Path Dellsmbios:\PowerManagement\WakeOnLANorWLAN -Value "LANorWLAN"
#Change Asset Tag
Set-Item –Path DellSmbios:\SystemInformation\AssetTag MyAssetTag -Password dell123
#Set WWAN Connection AutoSense
Set-Item -Path Dellsmbios:\PowerManagement\ControlWWANRadio -Value Enabled
#Get Service Tag
Get-ChildItem DellSmbios:\SystemInformation\ServiceTag
#Get Boot Sequence
Get-ChildItem DellSmbios:\BootSequence\Bootsequence
#Enable PXE boot
Set-Item -Path Dellsmbios:\SystemConfiguration\"Integrated NIC" -Value "Enabled w PXE"
#>
}
function Validate-Elevated {
$UserIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$UserWP = New-Object Security.Principal.WindowsPrincipal($UserIdentity)
$ErrorActionPreference = "Stop"
try {
if ($UserWP.IsInRole("S-1-5-32-544")) {
$PBUEFI.Image = $ValidatedImage
$LabelUEFI.Visible = $true
Write-OutputBox -OutputBoxMessage "User has local administrative rights, and the tool was launched elevated" -Type "INFO: " -Object Logging
return $true
}
else {
$PBUEFI.Image = $ErrorImage
$LabelUEFI.Visible = $true
Write-OutputBox -OutputBoxMessage "The tool requires local administrative rights and was not launched elevated" -Type "ERROR: " -Object Logging
return $false
}
}
catch [System.Exception] {
Write-OutputBox -OutputBoxMessage "An error occured when attempting to query for elevation, possible due to issues contacting the domain or the tool is launched in a sub-domain. If used in a sub-domain, check the override checkbox to enable this tool" -Type "WARNING: " -Object Logging
$PBUEFI.Image = $ErrorImage
$LabelUEFI.Visible = $true
$ErrorActionPreference = "Continue"
}
}
function Validate-System {
param(
[parameter(Mandatory=$false)]
$OutPutBox = $true
)
Begin {
$ModelsArrayList = New-Object System.Collections.ArrayList
$ModelsArrayList.AddRange(@($SupportedModels))
$ManufacturersArrayList = New-Object System.Collections.ArrayList
$ManufacturersArrayList.AddRange(@($SupportedManufacturers))
}
Process {
$FoundManufacturer = $ManufacturersArrayList | ?{$_ -match $ComputerSystem.Manufacturer}
If ($FoundManufacturer) {
$FoundModel = $ModelsArrayList | ?{$_ -match $ComputerSystem.Model}
if ($FoundModel) {
If($OutPutBox){Write-OutputBox -OutputBoxMessage ("Supported model found (" + $FoundModel + ")") -Type "INFO: " -Object Logging}
$PBModel.Image = $ValidatedImage
$LabelSupportedModel.Visible = $true
return $true
} Else {
If($OutPutBox){Write-OutputBox -OutputBoxMessage "The detected model (" + $ComputerSystem.Model + ") is not supported." -Type "ERROR: " -Object Logging}
$PBModel.Image = $ErrorImage
$LabelSupportedModel.Visible = $true
return $false
}
} Else {
If($OutPutBox){Write-OutputBox -OutputBoxMessage ("The detected manufacturer (" + $ComputerSystem.Manufacturer + ") is not supported.") -Type "ERROR: " -Object Logging}
$PBModel.Image = $ErrorImage
$LabelSupportedModel.Visible = $true
return $false
}
}
}
function Validate-BIOSPassword {
If ($global:PreValidation -eq $false){return $false; break}
$sTestVal = "TestAsset"
#sPrevAssetTag = oEnvironment.Item("AssetTag")
If ($UseDellCCTK){
$result = Execute-DellCCTK -Parameters "--asset=" -PassThru
If ($DebugLog){Write-Host "[cctk --asset=] exitcode:" $result.ExitCode}
If ($DebugLog){Write-Host "[cctk --asset=] Error:" $result.StdErr}
If ($DebugLog){Write-Host "[cctk --asset=] Output:" $result.StdOut}
If ($result.ExitCode -eq 191 -or $result.ExitCode -eq 180){
Write-OutputBox -OutputBoxMessage ("The BIOS password is set. Will try to guess password") -Type "ERROR: " -Object Logging
Foreach ($password in $BIOSKnownUsedpwd){
$PlainPassword = Decrypt-String -Encrypted $password -Passphrase "SecureHostBaseline"
$result = Execute-DellCCTK -Parameters "--asset=$sTestVal --valsetuppwd=$PlainPassword" -PassThru
If ($result.ExitCode -eq 0){
Write-OutputBox -OutputBoxMessage "Successfully able to access BIOS settings using a known BIOS password" -Type "INFO: " -Object Logging
$BIOSPasswordFound = $PlainPassword
Break
} Else {
Write-OutputBox -OutputBoxMessage ("Tried $password, The BIOS password is invalid. Will try to guess password again") -Type "ERROR: " -Object Logging
$BIOSPasswordFound = $Null
Continue
}
}
} Elseif($result.ExitCode -eq 0) {
Write-OutputBox -OutputBoxMessage ("The BIOS password is blank. A password is required to be compliant.") -Type "WARNING: " -Object Logging
Execute-DellCCTK -Parameters "--asset="
$BIOSPasswordFound = $Null
$PBBIOSPassword.Image = $WarningImage
$LabelBIOSPassword.Visible = $true
return $false
} Else {
Write-OutputBox -OutputBoxMessage ("CCTK errored with exit code: " + $result.ExitCode) -Type "ERROR: " -Object Logging
$BIOSPasswordFound = $Null
$PBBIOSPassword.Image = $ErrorImage
$LabelBIOSPassword.Visible = $true
return $false
}
If ($BIOSPasswordFound){
Write-OutputBox -OutputBoxMessage ("The BIOS password is has been fo") -Type "INFO: " -Object Logging
Execute-DellCCTK -Parameters "--asset= --valsetuppwd=$BIOSPasswordFound"
$PBBIOSPassword.Image = $ValidatedImage
$LabelBIOSPassword.Visible = $true
return $true
}Else{