Skip to content

Commit

Permalink
Added Windows "Client" OS support for Assert-HasPrereqsForBitlocker f…
Browse files Browse the repository at this point in the history
…unction.
  • Loading branch information
Mike Nothhard committed Jun 24, 2019
1 parent ebb676e commit 2177b01
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Change log for xBitlocker

## Unreleased
- Fixed issue causing Assert-HasPrereqsForBitlocker to fail on Windows 10.
Credit: https://github.com/goldfinger2
([issue #47](https://github.com/PowerShell/xBitlocker/issues/47))

## 1.4.0.0

Expand Down
47 changes: 30 additions & 17 deletions Misc/xBitlockerCommon.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -788,29 +788,42 @@ function Assert-HasPrereqsForBitlocker

$hasAllPreReqs = $true

$blFeature = Get-WindowsFeature BitLocker
$blAdminToolsFeature = Get-WindowsFeature RSAT-Feature-Tools-BitLocker
$blAdminToolsRemoteFeature = Get-WindowsFeature RSAT-Feature-Tools-BitLocker-RemoteAdminTool

if ($blFeature.InstallState -ne 'Installed')
if ((Get-OSEdition) -like 'Client')
{
$hasAllPreReqs = $false

Write-Error 'The Bitlocker feature needs to be installed before the xBitlocker module can be used'
$blFeature = Get-WindowsOptionalFeature BitLocker
if ($blFeature.InstallState -ne 'Installed')
{
$hasAllPreReqs = $false
Write-Error 'The Bitlocker feature needs to be installed before the xBitlocker module can be used'
}
}

if ($blAdminToolsFeature.InstallState -ne 'Installed')
else
{
$hasAllPreReqs = $false
$blFeature = Get-WindowsFeature BitLocker
$blAdminToolsFeature = Get-WindowsFeature RSAT-Feature-Tools-BitLocker
$blAdminToolsRemoteFeature = Get-WindowsFeature RSAT-Feature-Tools-BitLocker-RemoteAdminTool

Write-Error 'The RSAT-Feature-Tools-BitLocker feature needs to be installed before the xBitlocker module can be used'
}
if ($blFeature.InstallState -ne 'Installed')
{
$hasAllPreReqs = $false

if ($blAdminToolsRemoteFeature.InstallState -ne 'Installed' -and (Get-OSEdition) -notmatch 'Core')
{
$hasAllPreReqs = $false
Write-Error 'The Bitlocker feature needs to be installed before the xBitlocker module can be used'
}

if ($blAdminToolsFeature.InstallState -ne 'Installed')
{
$hasAllPreReqs = $false

Write-Error 'The RSAT-Feature-Tools-BitLocker feature needs to be installed before the xBitlocker module can be used'
}

if ($blAdminToolsRemoteFeature.InstallState -ne 'Installed' -and (Get-OSEdition) -notmatch 'Core')
{
$hasAllPreReqs = $false

Write-Error 'The RSAT-Feature-Tools-BitLocker-RemoteAdminTool feature needs to be installed before the xBitlocker module can be used'
}

Write-Error 'The RSAT-Feature-Tools-BitLocker-RemoteAdminTool feature needs to be installed before the xBitlocker module can be used'
}

if ($hasAllPreReqs -eq $false)
Expand Down
55 changes: 55 additions & 0 deletions Tests/Unit/xBitlockerCommon.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,15 @@ try
)
}

function Get-WindowsOptionalFeature
{
param
(
[string]
$FeatureName
)
}

function Get-OSEdition
{

Expand Down Expand Up @@ -292,6 +301,36 @@ try
}
}

Context 'When OS is a Windows client' {
Mock -CommandName Get-OSEdition -MockWith {
return 'Client'
}

Mock -CommandName Get-WindowsOptionalFeature -MockWith {
param
(
[string]
$FeatureName
)

return @{
DisplayName = $FeatureName
Name = $FeatureName
InstallState = 'Installed'
}
}

It 'Should not generate any error messages' {
Mock -CommandName Write-Error
Assert-HasPrereqsForBitlocker
Assert-MockCalled -Command Write-Error -Exactly -Times 0 -Scope It
}

It 'Should run the Assert-HasPrereqsForBitlocker function without exceptions' {
{Assert-HasPrereqsForBitlocker} | Should -Not -Throw
}
}

Context 'When OS is Full Server without the required features installed' {
Mock -CommandName Get-OSEdition -MockWith {
return 'Server'
Expand Down Expand Up @@ -422,6 +461,22 @@ try
$OSVersion | Should -Be 'Server'
}

It 'Should return "Client" if the OS is a Windows Client' {
Mock -CommandName Get-ItemProperty -MockWith {
[PSCustomObject] @{
InstallationType = 'Client'
PSPath = 'Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion'
PSParentPath = 'Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\software\microsoft\windows nt'
PSChildName = 'currentversion'
PSDrive = 'HKLM'
PSProvider = 'Microsoft.PowerShell.Core\Registry'
}
}

$OSVersion = Get-OSEdition
$OSVersion | Should -Be 'Client'
}

It 'Should run without exceptions' {
Mock -CommandName Get-ItemProperty -MockWith {
[PSCustomObject] @{
Expand Down

0 comments on commit 2177b01

Please sign in to comment.