forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-ComputerInfo.Tests.ps1
More file actions
1407 lines (1239 loc) · 58.2 KB
/
Copy pathGet-ComputerInfo.Tests.ps1
File metadata and controls
1407 lines (1239 loc) · 58.2 KB
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
#
# TEST SPECIFIC HELPER METHODS FOR TESTING Get-ComputerInfo cmdlet
#
$computerInfoAll > $null
function Get-ComputerInfoForTest
{
param([string[]] $properties = $null, [bool] $forceRefresh = $false) # NOTE: $forceRefresh only applies to the case where $properties is null
$computerInfo = $null >$null # RETURN VALUE
if ( $properties )
{
return Get-ComputerInfo -Property $properties
}
else
{
if ( $forceRefresh -or $script:computerInfoAll -eq $null)
{
$script:computerInfoAll = Get-ComputerInfo
}
return $script:computerInfoAll
}
}
function Get-PropertyNamesForComputerInfoTest
{
$propertyNames = @()
$propertyNames += @("BiosBIOSVersion",
"BiosBuildNumber",
"BiosCaption",
"BiosCharacteristics",
"BiosCodeSet",
"BiosCurrentLanguage",
"BiosDescription",
"BiosEmbeddedControllerMajorVersion",
"BiosEmbeddedControllerMinorVersion",
"BiosFirmwareType",
"BiosIdentificationCode",
"BiosInstallableLanguages",
"BiosInstallDate",
"BiosLanguageEdition",
"BiosListOfLanguages",
"BiosManufacturer",
"BiosName",
"BiosOtherTargetOS",
"BiosPrimaryBIOS",
"BiosReleaseDate",
"BiosSerialNumber",
"BiosSMBIOSBIOSVersion",
"BiosSMBIOSPresent",
"BiosSMBIOSMajorVersion",
"BiosSMBIOSMinorVersion",
"BiosSoftwareElementState",
"BiosStatus",
"BiosTargetOperatingSystem",
"BiosVersion")
$propertyNames += @("CsAdminPasswordStatus",
"CsAutomaticManagedPagefile",
"CsAutomaticResetBootOption",
"CsAutomaticResetCapability",
"CsBootOptionOnLimit",
"CsBootOptionOnWatchDog",
"CsBootROMSupported",
"CsBootStatus",
"CsBootupState",
"CsCaption",
"CsChassisBootupState",
"CsChassisSKUNumber",
"CsCurrentTimeZone",
"CsDaylightInEffect",
"CsDescription",
"CsDNSHostName",
"CsDomain",
"CsDomainRole",
"CsEnableDaylightSavingsTime",
"CsFrontPanelResetStatus",
"CsHypervisorPresent",
"CsInfraredSupported",
"CsInitialLoadInfo",
"CsInstallDate",
"CsKeyboardPasswordStatus",
"CsLastLoadInfo",
"CsManufacturer",
"CsModel",
"CsName",
"CsNetworkAdapters",
"CsNetworkServerModeEnabled",
"CsNumberOfLogicalProcessors",
"CsNumberOfProcessors",
"CsOEMStringArray",
"CsPartOfDomain",
"CsPauseAfterReset",
"CsPCSystemType",
"CsPCSystemTypeEx",
"CsPhyicallyInstalledMemory",
"CsPowerManagementCapabilities",
"CsPowerManagementSupported",
"CsPowerOnPasswordStatus",
"CsPowerState",
"CsPowerSupplyState",
"CsPrimaryOwnerContact",
"CsPrimaryOwnerName",
"CsProcessors",
"CsResetCapability",
"CsResetCount",
"CsResetLimit",
"CsRoles",
"CsStatus",
"CsSupportContactDescription",
"CsSystemFamily",
"CsSystemSKUNumber",
"CsSystemType",
"CsThermalState",
"CsTotalPhysicalMemory",
"CsUserName",
"CsWakeUpType",
"CsWorkgroup")
$propertyNames += @("HyperVisorPresent",
"HyperVRequirementDataExecutionPreventionAvailable",
"HyperVRequirementSecondLevelAddressTranslation",
"HyperVRequirementVirtualizationFirmwareEnabled",
"HyperVRequirementVMMonitorModeExtensions")
$propertyNames += @("OsArchitecture",
"OsBootDevice",
"OsBuildNumber",
"OsBuildType",
"OsCodeSet",
"OsCountryCode",
"OsCSDVersion",
"OsCurrentTimeZone",
"OsDataExecutionPrevention32BitApplications",
"OsDataExecutionPreventionAvailable",
"OsDataExecutionPreventionDrivers",
"OsDataExecutionPreventionSupportPolicy",
"OsDebug",
"OsDistributed",
"OsEncryptionLevel",
"OsForegroundApplicationBoost",
"OsHardwareAbstractionLayer",
"OsHotFixes",
"OsInstallDate",
"OsLanguage",
"OsLastBootUpTime",
"OsLocale",
"OsLocaleID",
"OsManufacturer",
"OsMaxProcessMemorySize",
"OsMuiLanguages",
"OsName",
"OsNumberOfLicensedUsers",
"OsNumberOfUsers",
"OsOperatingSystemSKU",
"OsOrganization",
"OsOtherTypeDescription",
"OsPAEEnabled",
"OsPagingFiles",
"OsPortableOperatingSystem",
"OsPrimary",
"OsProductSuites",
"OsProductType",
"OsRegisteredUser",
"OsSerialNumber",
"OsServerLevel",
"OsServicePackMajorVersion",
"OsServicePackMinorVersion",
"OsSizeStoredInPagingFiles",
"OsStatus",
"OsSuites",
"OsSystemDevice",
"OsSystemDirectory",
"OsSystemDrive",
"OsTotalSwapSpaceSize",
"OsTotalVirtualMemorySize",
"OsTotalVisibleMemorySize",
"OsType",
"OsVersion",
"OsWindowsDirectory")
$propertyNames += @("KeyboardLayout",
"LogonServer",
"PowerPlatformRole",
"TimeZone")
$WindowsPropertyArray = @("WindowsBuildLabEx",
"WindowsCurrentVersion",
"WindowsEditionId",
"WindowsInstallationType",
"WindowsProductId",
"WindowsProductName",
"WindowsRegisteredOrganization",
"WindowsRegisteredOwner",
"WindowsSystemRoot",
"WindowsVersion",
"WindowsUBR")
if ([System.Management.Automation.Platform]::IsIoT)
{
Write-Verbose -Verbose -Message "WindowsInstallDateFromRegistry is not supported on IoT."
}
else
{
$WindowsPropertyArray += "WindowsInstallDateFromRegistry"
}
$propertyNames += $WindowsPropertyArray
return $propertyNames
}
function New-ExpectedComputerInfo
{
param([string[]]$propertyNames)
# P-INVOKE TYPE DEF START ******************************************
function Get-FirmwareType
{
$signature = @"
[DllImport("kernel32.dll")]
public static extern bool GetFirmwareType(ref uint firmwareType);
"@
Add-Type -MemberDefinition $signature -Name "Win32BiosFirmwareType" -Namespace Win32Functions -PassThru
}
function Get-PhysicallyInstalledSystemMemory
{
$signature = @"
[DllImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetPhysicallyInstalledSystemMemory(out ulong MemoryInKilobytes);
"@
Add-Type -MemberDefinition $signature -Name "Win32PhyicallyInstalledMemory" -Namespace Win32Functions -PassThru
}
function Get-PhysicallyInstalledSystemMemoryCore
{
$signature = @"
[DllImport("api-ms-win-core-sysinfo-l1-2-1.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetPhysicallyInstalledSystemMemory(out ulong MemoryInKilobytes);
"@
Add-Type -MemberDefinition $signature -Name "Win32PhyicallyInstalledMemory" -Namespace Win32Functions -PassThru
}
function Get-PowerDeterminePlatformRole
{
$signature = @"
[DllImport("Powrprof", EntryPoint = "PowerDeterminePlatformRoleEx", CharSet = CharSet.Ansi)]
public static extern uint PowerDeterminePlatformRoleEx(uint version);
"@
Add-Type -MemberDefinition $signature -Name "Win32PowerDeterminePlatformRole" -Namespace Win32Functions -PassThru
}
function Get-LCIDToLocaleName
{
$signature = @"
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern int LCIDToLocaleName(uint localeID, System.Text.StringBuilder localeName, int localeNameSize, int flags);
"@
Add-Type -MemberDefinition $signature -Name "Win32LCIDToLocaleNameDllName" -Namespace Win32Functions -PassThru
}
# P-INVOKE TYPE DEF END ******************************************
# HELPER METHODS RELYING ON P-INVOKE BEGIN ******************************************
function Get-BiosFirmwareType
{
[int]$firmwareType = 0
(Get-FirmwareType)::GetFirmwareType([ref]$firmwareType)
return $firmwareType
}
function Get-CsPhysicallyInstalledSystemMemory
{
param([bool]$isCore = $false)
# TODO: we need to add support for tests running on core
# but for now, test is for non-core
[int] $memoryInKilobytes = 0
if ($isCore)
{
(Get-PhysicallyInstalledSystemMemoryCore)::GetPhysicallyInstalledSystemMemory([ref]$memoryInKilobytes)
}
else
{
(Get-PhysicallyInstalledSystemMemory)::GetPhysicallyInstalledSystemMemory([ref]$memoryInKilobytes)
}
return $memoryInKilobytes
}
function Get-PowerPlatformRole
{
$version = 0x2
$powerRole = (Get-PowerDeterminePlatformRole)::PowerDeterminePlatformRoleEx($version)
if ($powerRole -gt 9)
{
$powerRole = 0
}
return $powerRole
}
# HELPER METHODS RELYING ON P-INVOKE END ******************************************
$cimClassList = @{}
function Get-CimClass
{
param([string]$className, [string] $namespace = "root\cimv2")
if (-not $cimClassList.ContainsKey($className))
{
$cimClassInstance = Get-CimInstance -ClassName $className -Namespace $namespace
$cimClassList.Add($className, $cimClassInstance)
}
return $cimClassList.Get_Item($className)
}
function Get-CimClassPropVal
{
param([string]$className, [string]$propertyName, [string] $namespace = "root\cimv2")
$cimClassInstance = Get-CimClass $className $namespace
$cimClassInstance.$propertyName
}
function Get-CsNetworkAdapters
{
$networkAdapters = @()
$adapters = Get-CimClass Win32_NetworkAdapter
$configs = Get-CimClass Win32_NetworkAdapterConfiguration
# easy-out: no adapters or configs
if (!$adapters -or !$configs) { return $null }
# build config hashtable
$configHash = @{}
foreach ($config in $configs)
{
if ($config.Index -ne $null)
{
$configHash.Add([string]$config.Index,$config)
}
}
# easy-out: no config hash items
if ($configHash.Count -eq 0) { return $null }
foreach ($adapter in $adapters)
{
# Easy skip: adapters that have a null connection status or null index
if (!$adapter.NetConnectionStatus) { continue }
# Easy skip: configHash does not contain adapter
if (!$configHash.ContainsKey([string]$adapter.Index)) { continue }
$connectionStatus = 13 # default NetConnectionStatus.Other
if ($adapter.NetConnectionStatus) { $connectionStatus = $adapter.NetConnectionStatus}
$config =$configHash.Item([string]$adapter.Index)
$dHCPEnabled = $null
$dHCPServer = $null
$ipAddresses = $null
if ($connectionStatus -eq 2) # 2 = NetConnectionStatus.Connected
{
$dHCPEnabled = $config.DHCPEnabled
$dHCPServer = $config.DHCPServer;
$ipAddresses = $config.IPAddress;
}
# new-up one adapter object
$properties =
@{
'Description'=$adapter.Description;
'ConnectionID'=$adapter.NetConnectionID;
'ConnectionStatus' = $connectionStatus;
'DHCPEnabled' = $dHCPEnabled;
'DHCPServer' = $dHCPServer;
'IPAddresses' = $ipAddresses;
}
$networkAdapter = New-Object -TypeName PSObject -Prop $properties
# add adapter to list
$networkAdapters += $networkAdapter
}
return $networkAdapters
}
function Get-CsProcessors
{
$processors = Get-CimClass Win32_Processor
if (!$processors) {return $null }
$csProcessors = @()
foreach ($processor in $processors)
{
# new-up one adapter object
$properties =
@{
'Name'=$processor.Name;
'Manufacturer'=$processor.Manufacturer;
'Description'=$processor.Description;
'Architecture'=$processor.Architecture;
'AddressWidth'=$processor.AddressWidth;
'Availability'=$processor.Availability;
'CpuStatus'=$processor.CpuStatus;
'CurrentClockSpeed'=$processor.CurrentClockSpeed;
'DataWidth'=$processor.DataWidth;
'MaxClockSpeed'=$processor.MaxClockSpeed;
'NumberOfCores'=$processor.NumberOfCores;
'NumberOfLogicalProcessors'=$processor.NumberOfLogicalProcessors;
'ProcessorID'=$processor.ProcessorID;
'ProcessorType'=$processor.ProcessorType;
'Role'=$processor.Role;
'SocketDesignation'=$processor.SocketDesignation;
'Status'=$processor.Status;
}
$csProcessor = New-Object -TypeName PSObject -Prop $properties
# add adapter to list
$csProcessors += $csProcessor
}
$csProcessors
}
function Get-OsHardwareAbstractionLayer
{
$hal = $null
$systemDirectory = Get-CimClassPropVal Win32_OperatingSystem SystemDirectory
$halPath = Join-Path -path $systemDirectory -ChildPath "hal.dll"
$query = 'SELECT * FROM CIM_DataFile Where Name="C:\WINDOWS\system32\hal.dll"'
$query = $query -replace '\\','\\'
$instance = Get-CimInstance -Query $query
if ($instance)
{
$hal = [string]$instance[0].CimInstanceProperties["Version"].Value
}
return $hal
}
function Get-OsHotFixes
{
$hotfixes = Get-CimClass Win32_QuickFixEngineering | Select-Object -Property HotFixID,Description,InstalledOn,FixComments
if (!$hotfixes) {return $null }
$osHotFixes = @()
foreach ($hotfix in $hotfixes)
{
$installedOn = $null
if ($hotfix.InstalledOn)
{
$installedOn = $hotfix.InstalledOn.ToString("M/d/yyyy")
}
# new-up one adapter object
$properties =
@{
'HotFixID'=$hotfix.HotFixID;
'Description'=$hotfix.Description;
'InstalledOn'=$installedOn;
'FixComments'=$hotfix.FixComments;
}
$osHotFix = New-Object -TypeName PSObject -Prop $properties
# add adapter to list
$osHotFixes += $osHotFix
}
$osHotFixes
}
function Get-OsInUseVirtualMemory
{
$osInUseVirtualMemory = $null
$os = Get-CimClass Win32_OperatingSystem
$totalVirtualMemorySize = $os.TotalVirtualMemorySize
$freeVirtualMemory = $os.FreeVirtualMemory
if (($totalVirtualMemorySize) -and ($freeVirtualMemory))
{
$osInUseVirtualMemory = $totalVirtualMemorySize - $freeVirtualMemory
}
return $osInUseVirtualMemory
}
function Get-OsServerLevel
{
# translated from cmldet logic (1) RegistryInfo.GetServerLevels; and (2) os.GetOtherInfo()
$subkey = 'Software\Microsoft\Windows NT\CurrentVersion\Server\ServerLevels'
$regKey = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey($subkey)
$serverLevels = @{}
try
{
if ($regKey -ne $null)
{
$serverLevelNames = $regKey.GetValueNames()
foreach ($serverLevelName in $serverLevelNames)
{
if ($regKey.GetValueKind($serverLevelName) -eq 4) # RegistryValueKind.DWord == 4
{
$val = $regKey.GetValue($serverLevelName)
$serverLevels.Add($serverLevelName, [System.Convert]::ToUInt32($val))
}
}
}
}
finally
{
if ($regKey -ne $null) { $regKey.Dispose()}
}
if ($serverLevels -eq $null -or $serverLevels.Count -eq 0)
{
return $null
}
[uint32]$rv
# computerinfo enum ServerLevel
# 0 = Unknown
# 1 = NanoServer
# 2 = ServerCore
# 3 = ServerCoreWithManagementTools
# 4 = FullServer
if ($serverLevels.ContainsKey("NanoServer") -and $serverLevels["NanoServer"] -eq 1)
{
$rv = 1 # NanoServer
}
elseif ($serverLevels.ContainsKey("ServerCore") -and $serverLevels["ServerCore"] -eq 1)
{
$rv = 2 # ServerCore
if ($serverLevels.ContainsKey("Server-Gui-Mgmt") -and $serverLevels["Server-Gui-Mgmt"] -eq 1)
{
$rv = 3 # ServerCoreWithManagementTools
if ($serverLevels.ContainsKey("Server-Gui-Shell") -and $serverLevels["Server-Gui-Shell"] -eq 1)
{
$rv = 4 # FullServer
}
}
}
return $rv
}
function Get-OsSuites
{
param($propertyName)
$osProductSuites = @()
$suiteMask = Get-CimClassPropVal Win32_OperatingSystem $propertyName
if ($suiteMask)
{
foreach($suite in [System.Enum]::GetValues('Microsoft.PowerShell.Commands.OSProductSuite'))
{
if (($suiteMask -band $suite) -ne 0)
{
$osProductSuites += $suite
}
}
}
return $osProductSuites
}
function Get-HyperVProperty
{
param([string]$propertyName)
$hypervisorPresent = Get-CimClassPropVal Win32_ComputerSystem HypervisorPresent
$dataExecutionPrevention_Available = $null
$secondLevelAddressTranslationExtensions = $null
$virtualizationFirmwareEnabled = $null
$vMMonitorModeExtensions = $null
if (($hypervisorPresent -ne $null) -and ($hypervisorPresent -ne $true))
{
$dataExecutionPrevention_Available = Get-CimClassPropVal Win32_OperatingSystem DataExecutionPrevention_Available
$secondLevelAddressTranslationExtensions = Get-CimClassPropVal Win32_Processor SecondLevelAddressTranslationExtensions
$virtualizationFirmwareEnabled = Get-CimClassPropVal Win32_Processor VirtualizationFirmwareEnabled
$vMMonitorModeExtensions = Get-CimClassPropVal Win32_Processor VMMonitorModeExtensions
}
switch ($propertyName)
{
"HyperVisorPresent" { return $hypervisorPresent }
"HyperVRequirementDataExecutionPreventionAvailable" { return $dataExecutionPrevention_Available }
"HyperVRequirementSecondLevelAddressTranslation"{ return $secondLevelAddressTranslationExtensions }
"HyperVRequirementVirtualizationFirmwareEnabled"{ return $virtualizationFirmwareEnabled }
"HyperVRequirementVMMonitorModeExtensions" { return $vMMonitorModeExtensions }
}
}
function Get-KeyboardLayout
{
$keyboards = Get-CimClass Win32_Keyboard
$result = $null
if ($keyboards)
{
# cmdlet code comment TODO: handle multiple keyboards?
# there might be several keyboards found. For the moment
# we display info for only one
$layout = $keyboards[0].Layout
try
{
$layoutAsHex = [System.Convert]::ToUInt32($layout, 16)
if ($layoutAsHex -ne $null)
{
$result = Convert-LocaleIdToLocaleName $layoutAsHex
}
}
catch
{
#swallow
}
}
return $result
}
function Get-OsLanguageName
{
# updated 21May 2016 to follow updated logic from cmdlet
$localeID = Get-CimClassPropVal Win32_OperatingSystem OSLanguage
return Convert-LocaleIdToLocaleName $localeID
}
function Convert-LocaleIdToLocaleName
{
# This is a migrated/translated version of the cmdlet method = LocaleIdToLocaleName()
# THIS is the comment from the cmdlet
# CoreCLR's System.Globalization.Culture does not appear to have a constructor
# that accepts an integer LocalID (LCID) value, so we'll PInvoke native code
# to get a locale name from an LCID value
param($localeID)
$sb = (New-Object System.Text.StringBuilder([int]85)) # 85 = Native.LOCALE_NAME_MAX_LENGTH
$len = (Get-LCIDToLocaleName)::LCIDToLocaleName($localeID, $sb, $sb.Capacity, 0)
if (($len -gt 0) -and ($sb.Length -gt 0))
{
return $sb.ToString()
}
return $null
}
function Get-Locale
{
# This is a migrated/translated version of the cmdlet method = Conversion.MakeLocale()
# This method first tries to convert the string to a hex value
# and get the CultureInfo object from that value.
# Failing that it attempts to retrieve the CultureInfo object
# using the locale string as passed.
$localeName = $null
$locale = Get-CimClassPropVal Win32_OperatingSystem Locale
if ($locale -ne $null)
{
#$localeAsHex = $locale -as [hex]
$localeAsHex = [System.Convert]::ToUInt32($locale, 16)
if ($localeAsHex -ne $null)
{
try
{
$localeName = Convert-LocaleIdToLocaleName $localeAsHex
}
catch
{
# swallow this
# DEBUGGING
#return $_.Exception.Message
}
}
if ($localeName -eq $null)
{
try
{
$cultureInfo = (New-Object System.Globalization.CultureInfo($locale))
$localeName = $cultureInfo.Name
}
catch
{
# swallow this
}
}
}
return $localeName
}
function Get-OsPagingFiles
{
$osPagingFiles = @()
$pageFileUsage = Get-CimClass Win32_PageFileUsage
if ($pageFileUsage -ne $null)
{
foreach ($pageFileItem in $pageFileUsage)
{
$osPagingFiles += $pageFileItem.Caption
}
}
return [string[]]$osPagingFiles
}
function Get-UnixSecondsToDateTime
{
param([string]$seconds)
$origin = New-Object -Type DateTime -ArgumentList 1970, 1, 1, 0, 0, 0, 0
$origin.AddSeconds($seconds)
}
function Get-WinNtCurrentVersion
{
# This method was translated/converted from cmdlet impl method = RegistryInfo.GetWinNtCurrentVersion();
param([string]$propertyName)
$key = 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion\'
$regValue = (Get-ItemProperty -Path $key -Name $propertyName -ErrorAction SilentlyContinue).$propertyName
if ($propertyName -eq "InstallDate")
{
# more complicated case: InstallDate
if ($regValue)
{
return Get-UnixSecondsToDateTime $regValue
}
}
else
{
return $regValue
}
return $null
}
function Get-ExpectedComputerInfoValue
{
param([string]$propertyName)
switch ($propertyName)
{
"BiosBIOSVersion" {return Get-CimClassPropVal Win32_bios BiosVersion}
"BiosBuildNumber" {return Get-CimClassPropVal Win32_bios BuildNumber}
"BiosCaption" {return Get-CimClassPropVal Win32_bios Caption}
"BiosCharacteristics" {return Get-CimClassPropVal Win32_bios BiosCharacteristics}
"BiosCodeSet" {return Get-CimClassPropVal Win32_bios CodeSet}
"BiosCurrentLanguage" {return Get-CimClassPropVal Win32_bios CurrentLanguage}
"BiosDescription" {return Get-CimClassPropVal Win32_bios Description}
"BiosEmbeddedControllerMajorVersion" {return Get-CimClassPropVal Win32_bios EmbeddedControllerMajorVersion}
"BiosEmbeddedControllerMinorVersion" {return Get-CimClassPropVal Win32_bios EmbeddedControllerMinorVersion}
"BiosFirmwareType" {return Get-BiosFirmwareType}
"BiosIdentificationCode" {return Get-CimClassPropVal Win32_bios IdentificationCode}
"BiosInstallableLanguages" {return Get-CimClassPropVal Win32_bios InstallableLanguages}
"BiosInstallDate" {return Get-CimClassPropVal Win32_bios InstallDate}
"BiosLanguageEdition" {return Get-CimClassPropVal Win32_bios LanguageEdition}
"BiosListOfLanguages" {return Get-CimClassPropVal Win32_bios ListOfLanguages}
"BiosManufacturer" {return Get-CimClassPropVal Win32_bios Manufacturer}
"BiosName" {return Get-CimClassPropVal Win32_bios Name}
"BiosOtherTargetOS" {return Get-CimClassPropVal Win32_bios OtherTargetOS}
"BiosPrimaryBIOS" {return Get-CimClassPropVal Win32_bios PrimaryBIOS}
"BiosReleaseDate" {return Get-CimClassPropVal Win32_bios ReleaseDate}
"BiosSerialNumber" {return Get-CimClassPropVal Win32_bios SerialNumber}
"BiosSMBIOSBIOSVersion" {return Get-CimClassPropVal Win32_bios SMBIOSBIOSVersion}
"BiosSMBIOSPresent" {return Get-CimClassPropVal Win32_bios SMBIOSPresent}
"BiosSMBIOSMajorVersion" {return Get-CimClassPropVal Win32_bios SMBIOSMajorVersion}
"BiosSMBIOSMinorVersion" {return Get-CimClassPropVal Win32_bios SMBIOSMinorVersion}
"BiosSoftwareElementState" {return Get-CimClassPropVal Win32_bios SoftwareElementState}
"BiosStatus" {return Get-CimClassPropVal Win32_bios Status}
"BiosSystemBiosMajorVersion" {return Get-CimClassPropVal Win32_bios SystemBiosMajorVersion}
"BiosSystemBiosMinorVersion" {return Get-CimClassPropVal Win32_bios SystemBiosMinorVersion}
"BiosTargetOperatingSystem" {return Get-CimClassPropVal Win32_bios TargetOperatingSystem}
"BiosVersion" {return Get-CimClassPropVal Win32_bios Version}
"CsAdminPasswordStatus" {return Get-CimClassPropVal Win32_ComputerSystem AdminPasswordStatus}
"CsAutomaticManagedPagefile" {return Get-CimClassPropVal Win32_ComputerSystem AutomaticManagedPagefile}
"CsAutomaticResetBootOption" {return Get-CimClassPropVal Win32_ComputerSystem AutomaticResetBootOption}
"CsAutomaticResetCapability" {return Get-CimClassPropVal Win32_ComputerSystem AutomaticResetCapability}
"CsBootOptionOnLimit" {return Get-CimClassPropVal Win32_ComputerSystem BootOptionOnLimit}
"CsBootOptionOnWatchDog" {return Get-CimClassPropVal Win32_ComputerSystem BootOptionOnWatchDog}
"CsBootROMSupported" {return Get-CimClassPropVal Win32_ComputerSystem BootROMSupported}
"CsBootStatus" {return Get-CimClassPropVal Win32_ComputerSystem BootStatus}
"CsBootupState" {return Get-CimClassPropVal Win32_ComputerSystem BootupState}
"CsCaption" {return Get-CimClassPropVal Win32_ComputerSystem Caption}
"CsChassisBootupState" {return Get-CimClassPropVal Win32_ComputerSystem ChassisBootupState}
"CsChassisSKUNumber" {return Get-CimClassPropVal Win32_ComputerSystem ChassisSKUNumber}
"CsCurrentTimeZone" {return Get-CimClassPropVal Win32_ComputerSystem CurrentTimeZone}
"CsDaylightInEffect" {return Get-CimClassPropVal Win32_ComputerSystem DaylightInEffect}
"CsDescription" {return Get-CimClassPropVal Win32_ComputerSystem Description}
"CsDNSHostName" {return Get-CimClassPropVal Win32_ComputerSystem DNSHostName}
"CsDomain" {return Get-CimClassPropVal Win32_ComputerSystem Domain}
"CsDomainRole" {return Get-CimClassPropVal Win32_ComputerSystem DomainRole}
"CsEnableDaylightSavingsTime" {return Get-CimClassPropVal Win32_ComputerSystem EnableDaylightSavingsTime}
"CsFrontPanelResetStatus" {return Get-CimClassPropVal Win32_ComputerSystem FrontPanelResetStatus}
"CsHypervisorPresent" {return Get-CimClassPropVal Win32_ComputerSystem HypervisorPresent}
"CsInfraredSupported" {return Get-CimClassPropVal Win32_ComputerSystem InfraredSupported}
"CsInitialLoadInfo" {return Get-CimClassPropVal Win32_ComputerSystem InitialLoadInfo}
"CsInstallDate" {return Get-CimClassPropVal Win32_ComputerSystem InstallDate}
"CsKeyboardPasswordStatus" {return Get-CimClassPropVal Win32_ComputerSystem KeyboardPasswordStatus}
"CsLastLoadInfo" {return Get-CimClassPropVal Win32_ComputerSystem LastLoadInfo}
"CsManufacturer" {return Get-CimClassPropVal Win32_ComputerSystem Manufacturer}
"CsModel" {return Get-CimClassPropVal Win32_ComputerSystem Model}
"CsName" {return Get-CimClassPropVal Win32_ComputerSystem Name}
"CsNetworkAdapters" { return Get-CsNetworkAdapters }
"CsNetworkServerModeEnabled" {return Get-CimClassPropVal Win32_ComputerSystem NetworkServerModeEnabled}
"CsNumberOfLogicalProcessors" {return [System.Environment]::GetEnvironmentVariable("NUMBER_OF_PROCESSORS")}
"CsNumberOfProcessors" {return Get-CimClassPropVal Win32_ComputerSystem NumberOfProcessors }
"CsOEMStringArray" {return Get-CimClassPropVal Win32_ComputerSystem OEMStringArray}
"CsPartOfDomain" {return Get-CimClassPropVal Win32_ComputerSystem PartOfDomain}
"CsPauseAfterReset" {return Get-CimClassPropVal Win32_ComputerSystem PauseAfterReset}
"CsPCSystemType" {return Get-CimClassPropVal Win32_ComputerSystem PCSystemType}
"CsPCSystemTypeEx" {return Get-CimClassPropVal Win32_ComputerSystem PCSystemTypeEx}
"CsPhyicallyInstalledMemory" {return Get-CsPhysicallyInstalledSystemMemory}
"CsPowerManagementCapabilities" {return Get-CimClassPropVal Win32_ComputerSystem PowerManagementCapabilities}
"CsPowerManagementSupported" {return Get-CimClassPropVal Win32_ComputerSystem PowerManagementSupported}
"CsPowerOnPasswordStatus" {return Get-CimClassPropVal Win32_ComputerSystem PowerOnPasswordStatus}
"CsPowerState" {return Get-CimClassPropVal Win32_ComputerSystem PowerState}
"CsPowerSupplyState" {return Get-CimClassPropVal Win32_ComputerSystem PowerSupplyState}
"CsPrimaryOwnerContact" {return Get-CimClassPropVal Win32_ComputerSystem PrimaryOwnerContact}
"CsPrimaryOwnerName" {return Get-CimClassPropVal Win32_ComputerSystem PrimaryOwnerName}
"CsProcessors" { return Get-CsProcessors }
"CsResetCapability" {return Get-CimClassPropVal Win32_ComputerSystem ResetCapability}
"CsResetCount" {return Get-CimClassPropVal Win32_ComputerSystem ResetCount}
"CsResetLimit" {return Get-CimClassPropVal Win32_ComputerSystem ResetLimit}
"CsRoles" {return Get-CimClassPropVal Win32_ComputerSystem Roles}
"CsStatus" {return Get-CimClassPropVal Win32_ComputerSystem Status}
"CsSupportContactDescription" {return Get-CimClassPropVal Win32_ComputerSystem SupportContactDescription}
"CsSystemFamily" {return Get-CimClassPropVal Win32_ComputerSystem SystemFamily}
"CsSystemSKUNumber" {return Get-CimClassPropVal Win32_ComputerSystem SystemSKUNumber}
"CsSystemType" {return Get-CimClassPropVal Win32_ComputerSystem SystemType}
"CsThermalState" {return Get-CimClassPropVal Win32_ComputerSystem ThermalState}
"CsTotalPhysicalMemory" {return Get-CimClassPropVal Win32_ComputerSystem TotalPhysicalMemory}
"CsUserName" {return Get-CimClassPropVal Win32_ComputerSystem UserName}
"CsWakeUpType" {return Get-CimClassPropVal Win32_ComputerSystem WakeUpType}
"CsWorkgroup" {return Get-CimClassPropVal Win32_ComputerSystem Workgroup}
"HyperVisorPresent" {return Get-HyperVProperty $propertyName}
"HyperVRequirementDataExecutionPreventionAvailable" {return Get-HyperVProperty $propertyName}
"HyperVRequirementSecondLevelAddressTranslation" {return Get-HyperVProperty $propertyName}
"HyperVRequirementVirtualizationFirmwareEnabled" {return Get-HyperVProperty $propertyName}
"HyperVRequirementVMMonitorModeExtensions" {return Get-HyperVProperty $propertyName}
"KeyboardLayout" {return Get-KeyboardLayout}
"LogonServer" {return [Microsoft.Win32.Registry]::GetValue("HKEY_Current_User\Volatile Environment", "LOGONSERVER", "")}
"OsArchitecture" {return Get-CimClassPropVal Win32_OperatingSystem OsArchitecture}
"OsBootDevice" {return Get-CimClassPropVal Win32_OperatingSystem BootDevice}
"OsBuildNumber" {return Get-CimClassPropVal Win32_OperatingSystem BuildNumber}
"OsBuildType" {return Get-CimClassPropVal Win32_OperatingSystem BuildType}
"OsCodeSet" {return Get-CimClassPropVal Win32_OperatingSystem CodeSet}
"OsCountryCode" {return Get-CimClassPropVal Win32_OperatingSystem CountryCode}
"OsCSDVersion" {return Get-CimClassPropVal Win32_OperatingSystem CSDVersion}
"OsCurrentTimeZone" {return Get-CimClassPropVal Win32_OperatingSystem CurrentTimeZone}
"OsDataExecutionPrevention32BitApplications" {return Get-CimClassPropVal Win32_OperatingSystem DataExecutionPrevention_32BitApplications}
"OsDataExecutionPreventionAvailable" {return Get-CimClassPropVal Win32_OperatingSystem DataExecutionPrevention_Available}
"OsDataExecutionPreventionDrivers" {return Get-CimClassPropVal Win32_OperatingSystem DataExecutionPrevention_Drivers}
"OsDataExecutionPreventionSupportPolicy" {return Get-CimClassPropVal Win32_OperatingSystem DataExecutionPrevention_SupportPolicy}
"OsDebug" {return Get-CimClassPropVal Win32_OperatingSystem Debug}
"OsDistributed" {return Get-CimClassPropVal Win32_OperatingSystem Distributed}
"OsEncryptionLevel" {return Get-CimClassPropVal Win32_OperatingSystem EncryptionLevel}
"OsForegroundApplicationBoost" {return Get-CimClassPropVal Win32_OperatingSystem ForegroundApplicationBoost}
# OsFreePhysicalMemory => fragile test: fluid/dynamic (see special cases)
#"OsFreeSpaceInPagingFiles" {return Get-CimClassPropVal Win32_OperatingSystem FreePhysicalMemory}
# OsFreeSpaceInPagingFiles => fragile test: fluid/dynamic (see special cases)
#"OsFreeSpaceInPagingFiles" {return Get-CimClassPropVal Win32_OperatingSystem FreeSpaceInPagingFiles}
# OsFreeVirtualMemory => fragile test: fluid/dynamic (see special cases)
#"OsFreeVirtualMemory" {return Get-CimClassPropVal Win32_OperatingSystem FreeVirtualMemory}
"OsHardwareAbstractionLayer" {return Get-OsHardwareAbstractionLayer}
"OsHotFixes" {return Get-OsHotFixes }
"OsInstallDate" {return Get-CimClassPropVal Win32_OperatingSystem InstallDate}
"OsInUseVirtualMemory" { return Get-OsInUseVirtualMemory }
"OsLanguage" {return Get-OsLanguageName}
"OsLastBootUpTime" {return Get-CimClassPropVal Win32_OperatingSystem LastBootUpTime}
# OsLocalDateTime => fragile test: fluid/dynamic (see special cases)
#"OsLocalDateTime" {return Get-CimClassPropVal Win32_OperatingSystem LocalDateTime}
"OsLocale" {return Get-Locale}
"OsLocaleID" {return Get-CimClassPropVal Win32_OperatingSystem Locale}
"OsManufacturer" {return Get-CimClassPropVal Win32_OperatingSystem Manufacturer}
"OsMaxNumberOfProcesses" {return Get-CimClassPropVal Win32_OperatingSystem MaxNumberOfProcesses}
"OsMaxProcessMemorySize" {return Get-CimClassPropVal Win32_OperatingSystem MaxProcessMemorySize}
"OsMuiLanguages" {return Get-CimClassPropVal Win32_OperatingSystem MuiLanguages}
"OsName" {return Get-CimClassPropVal Win32_OperatingSystem Caption}
"OsNumberOfLicensedUsers" {return Get-CimClassPropVal Win32_OperatingSystem NumberOfLicensedUsers}
# OsNumberOfProcesses => fragile test: fluid/dynamic
#"OsNumberOfProcesses" {return Get-CimClassPropVal Win32_OperatingSystem NumberOfProcesses}
"OsNumberOfUsers" {return Get-CimClassPropVal Win32_OperatingSystem NumberOfUsers}
"OsOperatingSystemSKU" {return Get-CimClassPropVal Win32_OperatingSystem OperatingSystemSKU}
"OsOrganization" {return Get-CimClassPropVal Win32_OperatingSystem Organization}
"OsOtherTypeDescription" {return Get-CimClassPropVal Win32_OperatingSystem OtherTypeDescription}
"OsPAEEnabled" {return Get-CimClassPropVal Win32_OperatingSystem PAEEnabled}
"OsPagingFiles" {return Get-OsPagingFiles}
"OsPortableOperatingSystem" {return Get-CimClassPropVal Win32_OperatingSystem PortableOperatingSystem}
"OsPrimary" {return Get-CimClassPropVal Win32_OperatingSystem Primary}
"OsProductSuites" {return Get-OsSuites OSProductSuite }
"OsProductType" {return Get-CimClassPropVal Win32_OperatingSystem ProductType}
"OsRegisteredUser" {return Get-CimClassPropVal Win32_OperatingSystem RegisteredUser}
"OsSerialNumber" {return Get-CimClassPropVal Win32_OperatingSystem SerialNumber}
"OsServerLevel" {return Get-OsServerLevel}
"OsServicePackMajorVersion" {return Get-CimClassPropVal Win32_OperatingSystem ServicePackMajorVersion}
"OsServicePackMinorVersion" {return Get-CimClassPropVal Win32_OperatingSystem ServicePackMinorVersion}
"OsSizeStoredInPagingFiles" {return Get-CimClassPropVal Win32_OperatingSystem SizeStoredInPagingFiles}
"OsStatus" {return Get-CimClassPropVal Win32_OperatingSystem Status}
"OsSuites" {return Get-OsSuites SuiteMask }
"OsSystemDevice" {return Get-CimClassPropVal Win32_OperatingSystem SystemDevice}
"OsSystemDirectory" {return Get-CimClassPropVal Win32_OperatingSystem SystemDirectory}
"OsSystemDrive" {return Get-CimClassPropVal Win32_OperatingSystem SystemDrive}
"OsTotalSwapSpaceSize" {return Get-CimClassPropVal Win32_OperatingSystem TotalSwapSpaceSize}
"OsTotalVirtualMemorySize" {return Get-CimClassPropVal Win32_OperatingSystem TotalVirtualMemorySize}
"OsTotalVisibleMemorySize" {return Get-CimClassPropVal Win32_OperatingSystem TotalVisibleMemorySize}
"OsType" {return Get-CimClassPropVal Win32_OperatingSystem OSType }
# OsUptime => fragile test: fluid/dynamic
#"OsUptime" {return Get-CimClassPropVal Win32_OperatingSystem Uptime}
"OsVersion" {return Get-CimClassPropVal Win32_OperatingSystem Version}
"OsWindowsDirectory" {return [System.Environment]::GetEnvironmentVariable("windir")}
"PowerPlatformRole" { return Get-PowerPlatformRole }
"TimeZone" {return ([System.TimeZoneInfo]::Local).DisplayName}
"WindowsBuildLabEx" { return Get-WinNtCurrentVersion BuildLabEx }
"WindowsCurrentVersion" { return Get-WinNtCurrentVersion CurrentVersion}
"WindowsEditionId" { return Get-WinNtCurrentVersion EditionID}
"WindowsInstallationType" { return Get-WinNtCurrentVersion InstallationType}
"WindowsInstallDateFromRegistry" { return Get-WinNtCurrentVersion InstallDate}
"WindowsProductId" { return Get-WinNtCurrentVersion ProductId}
"WindowsProductName" { return Get-WinNtCurrentVersion ProductName}
"WindowsRegisteredOrganization" {return Get-WinNtCurrentVersion RegisteredOrganization}
"WindowsRegisteredOwner" {return Get-WinNtCurrentVersion RegisteredOwner}
"WindowsVersion" {return Get-WinNtCurrentVersion ReleaseId}
"WindowsUBR" {return Get-WinNtCurrentVersion UBR}
"WindowsSystemRoot" {return [System.Environment]::GetEnvironmentVariable("SystemRoot")}
default {return "Unknown/unsupported propertyName = $propertyName"}
}
}
$expected = New-Object -TypeName PSObject
foreach ($propertyName in [string[]]$propertyNames)
{
$expected | Add-Member -MemberType NoteProperty -Name $propertyName -Value (Get-ExpectedComputerInfoValue $propertyName)
}
return $expected
}
#
# COMMON TEST HELPER METHODS
#
function Build-TestCases
{
param($observed, $expected)
$propertNames = Get-CommonProperties $observed $expected
$testCases = @()
foreach ($propertyName in [string[]]$propertNames)
{
$expectedValue = $expected.PsObject.Properties.Item($propertyName).Value
$observedValue = $observed.PsObject.Properties.Item($propertyName).Value
$testCase = @{
"Expected" = $expectedValue;
"Observed" = $observedValue;
"PropertyName" = $propertyName}
$testCases += $testCase
}
$testCases
}
function Get-CommonProperties
{
param($observed,$expected)
if (!$observed) { return $null }
if (!$expected) { return $null }
$propListObserved = $observed | Get-Member -MemberType Properties | Select-Object -ExpandProperty Name | Select-Object -Unique
$propListExpected = $expected | Get-Member -MemberType Properties | Select-Object -ExpandProperty Name | Select-Object -Unique
$propCount = [math]::max($propListObserved.Count,$propListExpected.Count)
$syncWinNum = [math]::round(($propCount/2),0)
$commonProp = Compare-Object -SyncWindow $syncWinNum -ReferenceObject $propListExpected -DifferenceObject $propListObserved -ExcludeDifferent -IncludeEqual