-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #574 from TheJumpCloud/UN-2212_Command_Template_Re…
…moving_Extra_BitLocker_Passwords UN-2212 Command Template for Removing Extra BitLocker Numerical Passwords
- Loading branch information
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
...Gallery/Windows Commands/Windows - Remove Extra Bitlocker Recovery Passwords.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#### Name | ||
|
||
Windows - Remove Extra Bitlocker Recovery Passwords | v1.0 JCCG | ||
|
||
#### commandType | ||
|
||
windows | ||
|
||
#### Command | ||
|
||
```powershell | ||
function Get-OsVolumeLetter { | ||
return Get-WmiObject -Class Win32_OperatingSystem -Property SystemDrive | Select-Object -ExpandProperty SystemDrive | ||
} | ||
function Remove-NonMatchingBitLockerRecoveryPasswords { | ||
try { | ||
$osVolumeLetter = Get-OsVolumeLetter | ||
$bitLockerVolume = Get-BitLockerVolume -MountPoint $osVolumeLetter | ||
if(!$bitLockerVolume) { | ||
Write-Host "$osVolumeLetter Volume does not have an associated BitLocker volume." | ||
exit 1 | ||
} | ||
$passwords = $bitLockerVolume.KeyProtector.Where({$_.KeyProtectorType -eq "RecoveryPassword"}) | ||
if(!$passwords) { | ||
Write-Host "The System Drive $osVolumeLetter does not have an available Recovery Key." | ||
exit 1 | ||
} | ||
$recoveryKey = $passwords[0].RecoveryPassword | ||
# Get all recovery keys that do not match the passed in key. | ||
$nonMatchingpswds = $bitLockerVolume.KeyProtector.Where({$_.RecoveryPassword -ne "$recoveryKey" -and $_.KeyProtectorType -eq "RecoveryPassword"}) | ||
foreach($pswd in $nonMatchingpswds) { | ||
$recoveryPasswords = $bitLockerVolume.KeyProtector.Where({$_.KeyProtectorType -eq "RecoveryPassword"}) | ||
$numPasswords = [int]$recoveryPasswords.count | ||
if($numPasswords -gt 1) { | ||
# Remove all non-matching keys. | ||
Remove-BitLockerKeyProtector -MountPoint $osVolumeLetter -KeyProtectorId $pswd.KeyProtectorId -ErrorAction Stop | ||
} | ||
} | ||
} | ||
catch { | ||
Write-Host "$_" | ||
exit 1 | ||
} | ||
} | ||
Remove-NonMatchingBitLockerRecoveryPasswords | ||
``` | ||
|
||
#### Description | ||
|
||
WARNING: This script attempts to remove extra Bitlocker Recovery passwords. Ideal use of this script would be at a time when there is a low chance of the device rebooting. | ||
|
||
#### _Import This Command_ | ||
|
||
To import this command into your JumpCloud tenant run the below command using the [JumpCloud PowerShell Module](https://github.com/TheJumpCloud/support/wiki/Installing-the-JumpCloud-PowerShell-Module) | ||
|
||
``` | ||
Import-JCCommand -URL "https://github.com/TheJumpCloud/support/blob/master/PowerShell/JumpCloud%20Commands%20Gallery/Windows%20Commands/Windows%20-%20Remove%20Extra%20Bitlocker%20Recovery%20Passwords.md" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters