Skip to content

Commit 3475f35

Browse files
authored
Merge pull request #20 from PowerShell/dev
Release of version 1.2.0.0 of xBitlocker
2 parents 0fec32f + 1bd93ed commit 3475f35

File tree

14 files changed

+1163
-131
lines changed

14 files changed

+1163
-131
lines changed

.codecov.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
codecov:
2+
notify:
3+
require_ci_to_pass: no
4+
5+
comment:
6+
layout: "reach, diff"
7+
behavior: default
8+
9+
coverage:
10+
range: 50..80
11+
round: down
12+
precision: 0
13+
14+
status:
15+
project:
16+
default:
17+
# Set the overall project code coverage requirement to 70%
18+
target: 70
19+
patch:
20+
default:
21+
# Set the pull request requirement to not regress overall coverage by more than 5%
22+
# and let codecov.io set the goal for the code changed in the patch.
23+
target: auto
24+
threshold: 5

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
DSCResource.Tests
2+
.vs
3+
.vscode
4+
node_modules

.markdownlint.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"default": true,
3+
"MD029": {
4+
"style": "one"
5+
},
6+
"MD013": true,
7+
"MD024": false,
8+
"MD034": false,
9+
"no-hard-tabs": true
10+
}

.vscode/settings.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"powershell.codeFormatting.openBraceOnSameLine": false,
3+
"powershell.codeFormatting.newLineAfterOpenBrace": false,
4+
"powershell.codeFormatting.newLineAfterCloseBrace": true,
5+
"powershell.codeFormatting.whitespaceBeforeOpenBrace": true,
6+
"powershell.codeFormatting.whitespaceBeforeOpenParen": true,
7+
"powershell.codeFormatting.whitespaceAroundOperator": true,
8+
"powershell.codeFormatting.whitespaceAfterSeparator": true,
9+
"powershell.codeFormatting.ignoreOneLineBlock": false,
10+
"powershell.codeFormatting.preset": "Custom",
11+
"files.trimTrailingWhitespace": true,
12+
"files.insertFinalNewline": true
13+
}

DSCResources/MSFT_xBLAutoBitlocker/MSFT_xBLAutoBitlocker.psm1

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ function Get-TargetResource
7070
$UsedSpaceOnly
7171
)
7272

73-
#Load helper module Import-Module "$((Get-Item -LiteralPath "$($PSScriptRoot)").Parent.Parent.FullName)\Misc\xBitlockerCommon.psm1" -Verbose:0
73+
#Load helper module
74+
Import-Module "$((Get-Item -LiteralPath "$($PSScriptRoot)").Parent.Parent.FullName)\Misc\xBitlockerCommon.psm1" -Verbose:0
7475

7576
CheckForPreReqs
7677

@@ -151,8 +152,9 @@ function Set-TargetResource
151152
[System.Boolean]
152153
$UsedSpaceOnly
153154
)
154-
155-
#Load helper module Import-Module "$((Get-Item -LiteralPath "$($PSScriptRoot)").Parent.Parent.FullName)\Misc\xBitlockerCommon.psm1" -Verbose:0
155+
156+
#Load helper module
157+
Import-Module "$((Get-Item -LiteralPath "$($PSScriptRoot)").Parent.Parent.FullName)\Misc\xBitlockerCommon.psm1" -Verbose:0
156158

157159
CheckForPreReqs
158160

@@ -254,7 +256,8 @@ function Test-TargetResource
254256
$UsedSpaceOnly
255257
)
256258

257-
#Load helper module Import-Module "$((Get-Item -LiteralPath "$($PSScriptRoot)").Parent.Parent.FullName)\Misc\xBitlockerCommon.psm1" -Verbose:0
259+
#Load helper module
260+
Import-Module "$((Get-Item -LiteralPath "$($PSScriptRoot)").Parent.Parent.FullName)\Misc\xBitlockerCommon.psm1" -Verbose:0
258261

259262
CheckForPreReqs
260263

@@ -372,10 +375,35 @@ function GetAutoBitlockerStatus
372375
{
373376
[Hashtable]$returnValue = @{}
374377

378+
# Convert DriveType into values returned by Win32_EncryptableVolume.VolumeType
379+
switch ($DriveType)
380+
{
381+
'Fixed'
382+
{
383+
$driveTypeValue = 1
384+
}
385+
'Removable'
386+
{
387+
$driveTypeValue = 2
388+
}
389+
}
390+
375391
foreach ($blv in $allBlvs)
376392
{
377393
$vol = $null
378-
$vol = Get-Volume -Path $blv.MountPoint -ErrorAction SilentlyContinue | where {$_.DriveType -like $DriveType}
394+
395+
$encryptableVolumes = Get-CimInstance -Namespace 'root\cimv2\security\microsoftvolumeencryption' -Class Win32_Encryptablevolume -ErrorAction SilentlyContinue
396+
397+
if (Split-Path -Path $blv.MountPoint -IsAbsolute)
398+
{
399+
# MountPoint is a Drive Letter
400+
$vol = $encryptableVolumes | Where-Object {($_.DriveLetter -eq $blv.Mountpoint) -and ($_.VolumeType -eq $driveTypeValue)}
401+
}
402+
else
403+
{
404+
# MountPoint is a path
405+
$vol = $encryptableVolumes | Where-Object {($_.DeviceID -eq $blv.Mountpoint) -and ($_.VolumeType -eq $driveTypeValue)}
406+
}
379407

380408
if ($vol -ne $null)
381409
{

Misc/xBitlockerCommon.psm1

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function EnableBitlocker
8686
{
8787
throw "A TpmProtector must be used if Pin is used."
8888
}
89-
89+
9090
if ($PSBoundParameters.ContainsKey("AdAccountOrGroupProtector") -and $PrimaryProtector -notlike "AdAccountOrGroupProtector" -and !(ContainsKeyProtector -Type "AdAccountOrGroup" -KeyProtectorCollection $blv.KeyProtector))
9191
{
9292
Write-Verbose "Adding AdAccountOrGroupProtector"
@@ -164,7 +164,7 @@ function EnableBitlocker
164164
$handledTpmAlready = $true
165165

166166
$params.Add("Pin", $Pin.Password)
167-
167+
168168
if ($PSBoundParameters.ContainsKey("StartupKeyProtector"))
169169
{
170170
$params.Add("TpmAndPinAndStartupKeyProtector", $true)
@@ -181,7 +181,7 @@ function EnableBitlocker
181181
$handledTpmAlready = $true
182182

183183
$params.Add("TpmAndStartupKeyProtector", $true)
184-
$params.Add("StartupKeyPath", $StartupKeyPath)
184+
$params.Add("StartupKeyPath", $StartupKeyPath)
185185
}
186186

187187

@@ -325,6 +325,11 @@ function TestBitlocker
325325
Write-Verbose "Unable to locate MountPoint: $($MountPoint)"
326326
return $false
327327
}
328+
elseif ($blv.VolumeStatus -eq "FullyDecrypted")
329+
{
330+
Write-Verbose "MountPoint: $($MountPoint) Not Encrypted"
331+
return $false
332+
}
328333
elseif ($blv.KeyProtector -eq $null -or $blv.KeyProtector.Count -eq 0)
329334
{
330335
Write-Verbose "No key protectors on MountPoint: $($MountPoint)"
@@ -352,7 +357,7 @@ function TestBitlocker
352357
if ($PSBoundParameters.ContainsKey("Pin") -and !(ContainsKeyProtector -Type "TpmPin" -KeyProtectorCollection $blv.KeyProtector -StartsWith $true))
353358
{
354359
Write-Verbose "MountPoint '$($MountPoint) 'does not have TpmPin assigned."
355-
return $false
360+
return $false
356361
}
357362

358363
if ($PSBoundParameters.ContainsKey("RecoveryKeyProtector") -and !(ContainsKeyProtector -Type "ExternalKey" -KeyProtectorCollection $blv.KeyProtector))
@@ -383,7 +388,7 @@ function TestBitlocker
383388
{
384389
Write-Verbose "MountPoint '$($MountPoint) 'does not have TPM + StartupKey protector."
385390
return $false
386-
}
391+
}
387392
}
388393
}
389394

@@ -397,7 +402,7 @@ function TestBitlocker
397402
return $true
398403
}
399404

400-
#Ensures that required Bitlocker prereqs are installed
405+
#Ensures that required Bitlocker prereqs are installed
401406
function CheckForPreReqs
402407
{
403408
$hasAllPreReqs = $true
@@ -420,7 +425,7 @@ function CheckForPreReqs
420425
Write-Error "The RSAT-Feature-Tools-BitLocker feature needs to be installed before the xBitlocker module can be used"
421426
}
422427

423-
if ($blAdminToolsRemoteFeature.InstallState -ne "Installed")
428+
if ($blAdminToolsRemoteFeature.InstallState -ne 'Installed' -and (Get-OSEdition) -notmatch 'Core')
424429
{
425430
$hasAllPreReqs = $false
426431

@@ -513,4 +518,14 @@ function RemoveParameters
513518
}
514519
}
515520

521+
<#
522+
.SYNOPSIS
523+
Returns the OS edtion we currently running on
524+
#>
525+
function Get-OSEdition
526+
{
527+
(Get-ItemProperty -Path 'HKLM:/software/microsoft/windows nt/currentversion' -Name InstallationType).InstallationType
528+
}
529+
530+
516531
Export-ModuleMember -Function *

0 commit comments

Comments
 (0)