Skip to content
Menu

Turn on BitLocker and Store the Recovery Key

Encrypts the Windows drive with BitLocker and a TPM protector, storing the recovery key in Entra ID, Active Directory or a configured secure RMM field before encrypting.

Turn on BitLocker and store the recovery key is free for members.

Enter your email to create your free account and get the file.

We'll email you the script and the weekly MSP Outpost email. Unsubscribe anytime. Privacy policy.

Already a member? Sign in.

Be the first to review Turn on BitLocker and store the recovery key. Tell other MSPs how it worked for you.

Write a Review

LanguagePowerShell
Runs onWindows 10, Windows 11, Windows Server 2016+; runs as SYSTEM
NeedsPowerShell 5.1, administrator rights, TPM 1.2 or 2.0 ready, Windows Pro or higher
Changes thingsChanges what it runs on

What It Does

The script protects the Windows drive, the one holding C:\Windows. If the drive is not encrypted it adds a recovery password protector, stores the key, then starts encryption with the TPM protector. If it is encrypted with protection off, as Windows 11 automatic device encryption often leaves it, it adds the missing protectors, stores the key and resumes protection. If it is already protected, the script leaves a workgroup drive alone. On a joined PC it adds or backs up the recovery key if the drive has none or if the PC is Entra-joined and backup evidence for the current key is missing. An AD-only PC with a recovery key is left alone because the script cannot verify its backup from the PC.

The key goes to Microsoft Entra ID when the PC is Entra joined, to Active Directory when it is domain joined, and to both when hybrid. With EscrowRequired true, the default, and neither available, it ends in ERROR before encrypting anything. It checks for a ready TPM when it needs to add a TPM protector.

On a workgroup PC, set EscrowRequired to false and name a ResultField. The recovery password is then written to that RMM custom field before encryption starts and nowhere else. Make it a secure field. The recovery password is never printed, logged or put in the answer or the rows, which show only the key protector IDs. Without a ResultField, or on an RMM the library cannot write to, it refuses before changing anything.

Encryption starts with no restart test, so if the firmware cannot release the key from the TPM, the PC asks for the 48-digit recovery password at the next start. If a step fails after the recovery protector was added and encryption has not started, the protector it added is removed again. Data drives and other protectors are not touched.

Before You Run It

  • Run it with DryRun=true first. It ends in ERROR when the key could not be stored.
  • Do not use it on a PC you cannot reach when no one holds the recovery key.
  • BitLocker needs Windows Pro, Enterprise or Education, and a recovery partition. Home is skipped.
  • On a workgroup PC, create a secure RMM custom field, set EscrowRequired=false and pass the field name as ResultField before you enable or resume protection.

Type and Risk

  • Type: Action. It makes its change, checks the change worked and says what changed. It exits 0, or 2 when it could not do the job.
  • Risk: Low. Set DryRun=true, or run it with -WhatIf, to list every change without making any.
  • What it changes: Adds BitLocker key protectors to the Windows drive, backs up the recovery key to Entra ID or Active Directory (or the RMM field), starts encryption.
  • Restart: It never restarts the machine.
  • Typical run: Under 2 minutes; encryption continues in the background.
  • Example answer: "BitLocker enabled on C: (XtsAes256, used space only); key escrowed to Entra ID; protector IDs RP {1111aaaa-0000-0000-0000-000000000001} TPM {2222bbbb-0000-0000-0000-000000000002}"
  • Tested before listing on Windows 11 with Windows PowerShell 5.1, run as SYSTEM, against its own test cases.

Inputs

Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.

  • EscrowRequired: true (default): refuse to encrypt unless the recovery key can be stored in Entra ID or Active Directory. false: when neither exists, put the recovery password in ResultField instead.
  • EncryptionMethod: XtsAes256 (default), XtsAes128, Aes256 or Aes128.

Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.

License

Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.

The Script

enable-bitlocker.ps1 · 985 lines · 52.5 KB

Free for Members

Create a free account or sign in to read, copy and download this script.

Welcome Back

Sign in to your MSP Outpost account.