Skip to main content

Initialize BitLocker

Description

This script serves as the enforcement engine that automatically corrects BitLocker configuration issues identified by the detection logic. Designed as a wrapper for an agnostic encryption solution, it first prepares the environment by ensuring the correct security protocols (TLS 1.2/1.3) are active and establishing a secure working directory. It then parses the same custom fields to understand the required policy. Based on the current state of the drive, the script performs intelligent remediation actions: it will inject a missing Recovery Password without decrypting, or fully disable and re-encrypt the drive if the encryption algorithm or key protector type is incorrect. If decryption is required, the script enters a monitored wait loop to ensure the drive is fully clean before re-attempting encryption. Finally, it executes the core encryption logic to apply the correct settings, ensuring the device becomes fully compliant without requiring manual administrator intervention.

Crucially, this script performs a mandatory post-execution audit regardless of the initialization outcome (success or failure). It captures the current BitLocker state—including active Recovery Passwords—and writes them immediately to NinjaOne Custom Fields. This acts as a safety net, ensuring that recovery keys are stored in the RMM immediately. This is vital for devices without TPMs (using RecoveryPassword protectors), where a drive might lock before keys have time to sync to Active Directory or Azure AD, preventing potential data loss.

Note:

  • This is only compatible for Windows devices.
  • If no mount point is provided in the Custom field, it will encrypt "C" Drive by default.
  • The BitLocker Drive Encryption feature must be enabled on servers to encrypt a drive with BitLocker disk encryption. Encryption will not work without enabling this feature.

Requirements

  • PowerShell v5
  • Update the custom fields with the data so that script will use that settings.

Sample Run

SampleRun

Dependencies

Custom Fields

Field LabelScopeAccepted ValuesDefault ValueDescription
cPVAL MountPointOrganization, Location, DeviceDrive Letter (e.g., C: or D:)$env:SystemDriveThe drive letter to initialize BitLocker on.
cPVAL EncryptionMethodOrganization, Location, DeviceXTSAES128, XTSAES256, AES128, AES256XtsAes128The encryption algorithm to apply.
cPVAL KeyProtectorTypeOrganization, Location, DeviceTPM, TpmPin, TpmStartup, TpmPinStartup, Password, Startup, RecoveryKey, RecoveryPassword, AdAccountRecoveryPasswordThe primary authentication method used to unlock the drive.
cPVAL PIN Or PasswordOrganization, Location, DeviceString (Any valid PIN or Password)$nullRequired if TpmPin or Password is selected.
cPVAL Path Or ADAccountOrganization, Location, DeviceString (UNC Path, Drive Path, or AD User/Group)$nullRequired for Startup, RecoveryKey, or AdAccount.
cPVAL Allow TPM Or RebootOrganization, Location, Device0 = None1 = Allow TPM Init2 = Allow Restart3 = Allow Both0Controls if the script can initialize TPM or reboot the machine.
cPVAL SkipHardwareTestOrganization, Location, Device$falseSkips the hardware pre-check (faster, but riskier).
cPVAL BitLocker InfoDeviceStores the HTML-formatted inventory of BitLocker volumes and protectors.
cPVAL BitLocker Enabled for System DriveDeviceindicating if the Operating System drive is encrypted.

Automation Setup/Import

Automation Configuration

Output

  • Activity Logs
  • Custom Fields
    • cPVAL BitLocker Info
      Image1
    • cPVAL BitLocker Enabled for System Drive
      Image2