Skip to main content

Enable BitLocker & Backup Key to Entra ID

A production-ready PowerShell script to enable BitLocker encryption on a Windows 11 device and automatically back up the recovery key to Microsoft Entra ID (formerly Azure AD).

5 min readUpdated March 29, 2026

Overviewsection

This script enables BitLocker on the OS drive using the TPM protector, adds a recovery password, and backs up the recovery key to Microsoft Entra ID (formerly Azure AD) — all in one step. It is designed to be deployed via Intune, SCCM, or run manually on individual machines.

Prerequisitessection

  • Windows 11 Pro, Enterprise, or Education
  • TPM 2.0 chip present and enabled
  • Device joined to Microsoft Entra ID (or hybrid joined)
  • PowerShell 5.1 or later (PowerShell 7.6 LTS recommended) running as Administrator

The Scriptsection

powershell
<#
.SYNOPSIS
    Enable BitLocker and back up the recovery key to Microsoft Entra ID.
.DESCRIPTION
    Checks for TPM, enables BitLocker with XTS-AES-256 encryption,
    adds a recovery password protector, and backs up to Microsoft Entra ID.
    Safe to run on devices that are already encrypted — it will
    only back up the existing key.
.PARAMETER MountPoint
    The drive to encrypt. Defaults to C:
#>

param(
    [string]$MountPoint = "C:"
)

# Require admin
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
    Write-Error "This script must be run as Administrator."
    exit 1
}

# Check for TPM
$tpm = Get-Tpm -ErrorAction SilentlyContinue
if (-not $tpm.TpmPresent) {
    Write-Error "No TPM detected. BitLocker requires a TPM 2.0 chip."
    exit 1
}

if (-not $tpm.TpmReady) {
    Write-Warning "TPM is present but not ready. Attempting to initialize..."
    Initialize-Tpm -ErrorAction Stop
}

# Check current BitLocker status
$volume = Get-BitLockerVolume -MountPoint $MountPoint -ErrorAction Stop

if ($volume.VolumeStatus -eq "FullyEncrypted") {
    Write-Host "Drive $MountPoint is already encrypted." -ForegroundColor Green

    # Ensure a recovery password protector exists
    $recoveryProtector = $volume.KeyProtector | Where-Object { $_.KeyProtectorType -eq 'RecoveryPassword' }

    if (-not $recoveryProtector) {
        Write-Host "Adding recovery password protector..."
        $result = Add-BitLockerKeyProtector -MountPoint $MountPoint -RecoveryPasswordProtector
        $recoveryProtector = $result.KeyProtector | Where-Object { $_.KeyProtectorType -eq 'RecoveryPassword' }
    }
} elseif ($volume.VolumeStatus -eq "EncryptionInProgress") {
    Write-Host "Encryption is already in progress. Waiting..."
    $recoveryProtector = $volume.KeyProtector | Where-Object { $_.KeyProtectorType -eq 'RecoveryPassword' }
} else {
    Write-Host "Enabling BitLocker on $MountPoint..."

    # Enable BitLocker with TPM protector
    Enable-BitLocker -MountPoint $MountPoint `
        -EncryptionMethod XtsAes256 `
        -TpmProtector `
        -SkipHardwareTest `
        -ErrorAction Stop

    # Add recovery password protector
    $result = Add-BitLockerKeyProtector -MountPoint $MountPoint -RecoveryPasswordProtector
    $recoveryProtector = $result.KeyProtector | Where-Object { $_.KeyProtectorType -eq 'RecoveryPassword' }

    Write-Host "BitLocker enabled. Encryption is now in progress." -ForegroundColor Green
}

# Back up recovery key to Microsoft Entra ID (cmdlet retains AAD name for backward compatibility)
if ($recoveryProtector) {
    try {
        BackupToAAD-BitLockerKeyProtector -MountPoint $MountPoint -KeyProtectorId $recoveryProtector.KeyProtectorId -ErrorAction Stop
        Write-Host "Recovery key backed up to Microsoft Entra ID successfully." -ForegroundColor Green
        Write-Host "Key ID: $($recoveryProtector.KeyProtectorId)" -ForegroundColor Cyan
    } catch {
        Write-Warning "Failed to back up to Microsoft Entra ID: $_"
        Write-Warning "Recovery password (SAVE THIS): $($recoveryProtector.RecoveryPassword)"
    }
} else {
    Write-Error "No recovery password protector found. Cannot back up."
    exit 1
}

# Display final status
$finalVolume = Get-BitLockerVolume -MountPoint $MountPoint
Write-Host "`n--- BitLocker Status ---" -ForegroundColor Cyan
Write-Host "Volume:     $MountPoint"
Write-Host "Status:     $($finalVolume.VolumeStatus)"
Write-Host "Encryption: $($finalVolume.EncryptionMethod)"
Write-Host "Protectors: $($finalVolume.KeyProtector.Count)"
Write-Host "Key ID:     $($recoveryProtector.KeyProtectorId)"

Usagesection

Run manually on a single devicesection

powershell
.\Enable-BitLockerAzureAD.ps1

Deploy via Intune as a PowerShell scriptsection

  1. Go to intune.microsoft.com > Devices > Scripts and remediations > Platform scripts
  2. Click Add > Windows 10 and later
  3. Upload the script
  4. Configure:
    • Run this script using the logged-on credentials: No (runs as SYSTEM)
    • Enforce script signature check: No (or sign the script)
    • Run script in 64-bit PowerShell: Yes
  5. Assign to a device group

Deploy via SCCM / MECMsection

Create a Package or Task Sequence step that runs:

powershell.exe -ExecutionPolicy Bypass -File .\Enable-BitLockerAzureAD.ps1

How It Workssection

  1. Checks for TPM — exits if no TPM 2.0 is present
  2. Checks if already encrypted — if yes, only ensures a recovery protector exists
  3. Enables BitLocker — uses XTS-AES-256 (the strongest available encryption method)
  4. Adds recovery password — the 48-digit key that can unlock the drive if the TPM fails
  5. Backs up to Microsoft Entra ID — stores the recovery key in Microsoft Entra ID against the device object
  6. Reports final status — displays the encryption state and key ID
Warning

The -SkipHardwareTest flag starts encryption immediately without a reboot test. This is intentional for automated deployments. For manual single-device runs, you can remove this flag to test the TPM before encrypting.

Verifying the Backupsection

From the Microsoft Entra Admin Centersection

  1. Go to entra.microsoft.com > Devices > search for the device
  2. Click BitLocker keys
  3. Confirm the Key ID matches the script output

From PowerShellsection

powershell
# Requires Microsoft Graph module
Connect-MgGraph -Scopes "BitLockerKey.Read.All"
Get-MgInformationProtectionBitlockerRecoveryKey -Filter "deviceId eq 'DEVICE-ID'"

Troubleshootingsection

ErrorCauseFix
"No TPM detected"TPM not enabled in BIOSEnter BIOS, enable TPM / Intel PTT / AMD fTPM
"BitLocker could not be enabled"Drive has no compatible partitionRun bdehdcfg -target default to prepare the drive
"BackupToAAD-BitLockerKeyProtector failed"Device not Microsoft Entra ID joinedRun dsregcmd /status to check join status
"Access denied"Script not running as adminRun PowerShell as Administrator

Need help with BitLocker administration?section

For a specific device or recovery-key backup problem, see on-demand remote IT support. For ongoing administration across your fleet, explore managed IT support.

PowerShellBitLockerMicrosoft Entra IDEncryptionAutomation

Was this article helpful?