8000 [Feature] · PowerShell/PowerShell@700a1c4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 700a1c4

Browse files
committed
[Feature]
fix Get-ComputerInfo return of status for DeviceGuard fix corresponding tests
1 parent 4df979a commit 700a1c4

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

src/Microsoft.PowerShell.Commands.Management/commands/management/GetComputerInfoCommand.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,14 @@ private static DeviceGuardInfo GetDeviceGuard(CimSession session)
436436
var wmiGuard = session.GetFirst<WmiDeviceGuard>(CIMHelper.DeviceGuardNamespace,
437437
CIMHelper.ClassNames.DeviceGuard);
438438

439-
if (wmiGuard != null)
439+
if (wmiGuard != null) {
440+
var smartStatus = EnumConverter<DeviceGuardSmartStatus>.Convert((int?)wmiGuard.VirtualizationBasedSecurityStatus ?? 0);
441+
if (smartStatus != null)
442+
{
443+
status = (DeviceGuardSmartStatus)smartStatus;
444+
}
440445
guard = wmiGuard.AsOutputType;
446+
}
441447
}
442448

443449
return new DeviceGuardInfo

test/powershell/Modules/Microsoft.PowerShell.Management/Get-ComputerInfo.Tests.ps1

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@ function Get-ComputerInfoForTest
2323
}
2424
}
2525

26+
function Get-StringValuesFromValueMap
27+
{
28+
param([string[]] $values, [hashtable] $valuemap)
29+
30+
[string] $stringValues = [string]::Empty
31+
32+
foreach ($value in $values)
33+
{
34+
if ($stringValues -ne [string]::Empty)
35+
{
36+
$stringValues += ","
37+
}
38+
$stringValues += $valuemap[$value]
39+
}
40+
$stringValues
41+
}
42+
2643
function Get-PropertyNamesForComputerInfoTest
2744
{
2845
$propertyNames = @()
@@ -1346,11 +1363,30 @@ try {
13461363
else
13471364
{
13481365
$deviceGuard = Get-DeviceGuard
1349-
$observed.DeviceGuardSmartStatus | Should Be $deviceGuard.SmartStatus
1350-
$observed.DeviceGuardRequiredSecurityProperties | Should Be $deviceGuard.RequiredSecurityProperties
1366+
# can't get amended qualifiers using cim cmdlets so we define them here
1367+
$requiredSecurityPropertiesValues = @{
1368+
"1" = "BaseVirtualizationSupport"
1369+
"2" = "SecureBoot"
1370+
"3" = "DMAProtection"
1371+
"4" = "SecureMemoryOverwrite"
1372+
"5" = "UEFICodeReadonly"
1373+
"6" = "SMMSecurityMitigations1.0"
1374+
}
1375+
$smartStatusValues = @{
1376+
"0" = "Off"
1377+
"1" = "Enabled"
1378+
"2" = "Running"
1379+
}
1380+
$securityServicesRunningValues = @{
1381+
"0" = "0"
1382+
"1" = "CredentialGuard"
1383+
"2" = "HypervisorEnforcedCodeIntegrity"
1384+
}
1385+
$observed.DeviceGuardSmartStatus | Should Be (Get-StringValuesFromValueMap -valuemap $smartStatusValues -values $deviceGuard.SmartStatus)
1386+
[string]::Join(",", $observed.DeviceGuardRequiredSecurityProperties) | Should Be (Get-StringValuesFromValueMap -valuemap $requiredSecurityPropertiesValues -values $deviceGuard.RequiredSecurityProperties)
13511387
$observed.DeviceGuardAvailableSecurityProperties | Should Be $deviceGuard.AvailableSecurityProperties
13521388
$observed.DeviceGuardSecurityServicesConfigured | Should Be $deviceGuard.SecurityServicesConfigured
1353-
$observed.DeviceGuardSecurityServicesRunning | Should Be $deviceGuard.SecurityServicesRunning
1389+
[string]::Join(",", $observed.DeviceGuardSecurityServicesRunning) | Should Be (Get-StringValuesFromValueMap -valuemap $securityServicesRunningValues -values $deviceGuard.SecurityServicesRunning)
13541390
$observed.DeviceGuardCodeIntegrityPolicyEnforcementStatus | Should Be $deviceGuard.CodeIntegrityPolicyEnforcementStatus
13551391
$observed.DeviceGuardUserModeCodeIntegrityPolicyEnforcementStatus | Should Be $deviceGuard.UserModeCodeIntegrityPolicyEnforcementStatus
13561392
}

0 commit comments

Comments
 (0)
0