Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Windows 10 OS support. Fixes #47 #52

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## 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

- Change double quoted string literals to single quotes
Expand Down
8 changes: 6 additions & 2 deletions DSCResources/MSFT_xBLAutoBitlocker/MSFT_xBLAutoBitlocker.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,9 @@ function Set-TargetResource
else
{
Remove-FromPSBoundParametersUsingHashtable -PSBoundParametersIn $PSBoundParameters -ParamsToRemove 'DriveType', 'MinDiskCapacityGB'
Add-ToPSBoundParametersFromHashtable -PSBoundParametersIn $PSBoundParameters -ParamsToAdd @{'MountPoint' = ''}
Add-ToPSBoundParametersFromHashtable -PSBoundParametersIn $PSBoundParameters -ParamsToAdd @{
'MountPoint' = ''
}

# Loop through each potential AutoBitlocker volume, see whether they are enabled for Bitlocker, and if not, enable it
foreach ($key in $autoBlVols.Keys)
Expand Down Expand Up @@ -575,7 +577,9 @@ function Test-TargetResource
else
{
Remove-FromPSBoundParametersUsingHashtable -PSBoundParametersIn $PSBoundParameters -ParamsToRemove 'DriveType', 'MinDiskCapacityGB'
Add-ToPSBoundParametersFromHashtable -PSBoundParametersIn $PSBoundParameters -ParamsToAdd @{'MountPoint' = ''}
Add-ToPSBoundParametersFromHashtable -PSBoundParametersIn $PSBoundParameters -ParamsToAdd @{
'MountPoint' = ''
}

# Check whether any potential AutoBitlocker volume is not currently enabled for Bitlocker, or doesn't have the correct settings
foreach ($key in $autoBlVols.Keys)
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 -Online -FeatureName 'BitLocker'
if ($blFeature.State -ne 'Enabled')
{
$hasAllPreReqs = $false
Write-Error -Message '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 -Name 'BitLocker'
$blAdminToolsFeature = Get-WindowsFeature -Name 'RSAT-Feature-Tools-BitLocker'
$blAdminToolsRemoteFeature = Get-WindowsFeature -Name '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 -Message 'The Bitlocker feature needs to be installed before the xBitlocker module can be used'
}

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

Write-Error -Message '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 -Message '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
59 changes: 58 additions & 1 deletion Tests/Unit/xBitlockerCommon.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,16 @@ try
{
param
(
[string]
[String]
$FeatureName
)
}

function Get-WindowsOptionalFeature
{
param
(
[String]
$FeatureName
)
}
Expand Down Expand Up @@ -292,6 +301,38 @@ try
}
}

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

Mock -CommandName Get-WindowsOptionalFeature -MockWith {
param
(
[Switch]
$Online = $false,
[String]
$FeatureName
)

return @{
DisplayName = $FeatureName
Name = $FeatureName
State = 'Enabled'
}
}

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 +463,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