{"id":110,"date":"2026-03-11T12:55:20","date_gmt":"2026-03-11T12:55:20","guid":{"rendered":"https:\/\/unen.nl\/?p=110"},"modified":"2026-03-13T07:38:03","modified_gmt":"2026-03-13T07:38:03","slug":"powershell-%f0%9f%94%90-bitlocker-automatisch-controleren-en-inschakelen-met-powershell","status":"publish","type":"post","link":"https:\/\/unen.nl\/?p=110","title":{"rendered":"Powershell &#8211; \ud83d\udd10 BitLocker automatisch controleren en inschakelen met PowerShell"},"content":{"rendered":"\n<p>Beveiliging van endpoints is tegenwoordig geen luxe meer, maar een noodzaak. Gelukkig helpt Microsoft BitLocker daarbij door schijven te versleutelen. Maar wat als BitLocker nog niet actief is op een apparaat? Of als de recovery key niet goed is opgeslagen?<\/p>\n\n\n\n<p>Met dit PowerShell-script wordt dat automatisch gecontroleerd \u00e9n opgelost. \ud83d\ude80<\/p>\n\n\n\n<p>Het script controleert of BitLocker correct is ingesteld op een Windows-apparaat en voert waar nodig automatisch herstelacties uit. Ideaal voor beheer via <strong>Intune<\/strong>, <strong>beheerplatformen<\/strong> of handmatige deployments.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u2699\ufe0f Wat doet het script precies?<\/h2>\n\n\n\n<p>Het script voert meerdere controles uit om te garanderen dat BitLocker correct en veilig is geconfigureerd.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd0d Controle op TPM<\/h3>\n\n\n\n<p>Het script controleert eerst of er een <strong>TPM-chip aanwezig en klaar voor gebruik<\/strong> is. Zonder TPM kan BitLocker namelijk niet op de standaard veilige manier worden ingezet.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd10 BitLocker status controleren<\/h3>\n\n\n\n<p>Daarna wordt gecontroleerd of BitLocker al actief is op de systeemschijf.<\/p>\n\n\n\n<p>Is BitLocker nog niet ingeschakeld?<br>Dan wordt de versleuteling automatisch gestart met <strong>XTS-AES-256 encryptie<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udddd Recovery key controleren<\/h3>\n\n\n\n<p>Een recovery key is essentieel wanneer toegang tot het systeem verloren dreigt te gaan. Het script controleert daarom of een <strong>Recovery Password Protector<\/strong> aanwezig is.<\/p>\n\n\n\n<p>Ontbreekt deze? Dan wordt hij automatisch toegevoegd.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u2601\ufe0f Backup naar Entra ID \/ Azure AD<\/h3>\n\n\n\n<p>Voor centraal beheer wordt de recovery key automatisch <strong>geback-upt naar Entra ID (Azure AD)<\/strong>. Hierdoor kunnen beheerders de sleutel altijd terugvinden wanneer dat nodig is.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udcdd Logging en troubleshooting<\/h3>\n\n\n\n<p>Het script maakt uitgebreide logs met onder andere:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>uitvoerende gebruiker<\/li>\n\n\n\n<li>apparaatnaam<\/li>\n\n\n\n<li>IP-adressen<\/li>\n\n\n\n<li>encryptiestatus<\/li>\n\n\n\n<li>foutmeldingen<\/li>\n<\/ul>\n\n\n\n<p>Daarnaast wordt een <strong>transcriptbestand<\/strong> aangemaakt dat automatisch wordt gekopieerd naar de <strong>Intune Management Extension logs<\/strong>. Zo blijft troubleshooting eenvoudig.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udca1 Waarom dit handig is<\/h2>\n\n\n\n<p>In grotere omgevingen komt het regelmatig voor dat:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>BitLocker niet is ingeschakeld<\/li>\n\n\n\n<li>Recovery keys ontbreken<\/li>\n\n\n\n<li>Keys niet naar Entra ID zijn ge\u00fcpload<\/li>\n\n\n\n<li>TPM nog niet correct is ge\u00efnitialiseerd<\/li>\n<\/ul>\n\n\n\n<p>Dit script lost die problemen automatisch op en zorgt voor een <strong>consistente beveiligingsconfiguratie op alle apparaten<\/strong>.<\/p>\n\n\n\n<p>Perfect dus voor gebruik als:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Intune remediation script<\/li>\n\n\n\n<li>compliance fix<\/li>\n\n\n\n<li>deployment controle<\/li>\n\n\n\n<li>endpoint security automatisering<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udda5 Ondersteunde systemen<\/h2>\n\n\n\n<p>Het script werkt op:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Windows 10 Pro<\/li>\n\n\n\n<li>Windows 10 Enterprise<\/li>\n\n\n\n<li>Windows 10 Education<\/li>\n\n\n\n<li>Windows 11 Pro<\/li>\n\n\n\n<li>Windows 11 Enterprise<\/li>\n\n\n\n<li>Windows 11 Education<\/li>\n<\/ul>\n\n\n\n<p>Uitvoering moet plaatsvinden als <strong>Administrator of SYSTEM<\/strong>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udcbb Het PowerShell-script<\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\">param ([switch]$Silent)<br>&lt;#<br>    .NOTES<br>    ===========================================================================<br>     Created on:    2025-06-21<br>     Updated on:    2026-03-12<br>     Created by:    Vincent van Unen<br>     Filename:      SCA_BitlockercheckenFix.ps1<br>     Version:       1.3.1<br>    ===========================================================================<br>    .DESCRIPTION<br>        Remediation - BitLocker inschakelen en recovery key back-uppen<br>        - Controleert of TPM aanwezig en gereed is<br>        - Controleert of BitLocker al actief is, zo niet, dan wordt het ingeschakeld<br>        - Controleert of een Recovery Password protector aanwezig is, zo niet, dan wordt deze toegevoegd<br>        - Back-upt de recovery key naar Entra ID\/Azure AD (indien cmdlet beschikbaar)<br>        - Hard Block: stopt veilig als TPM reset\/herinitialisatie nodig lijkt<br>        - Pending reboot guard: voorkomt FVE_E_REBOOT_REQUIRED tijdens run<br>        - Geschikt voor Windows 10\/11 Pro, Enterprise en Education<br>        - Uitvoeren als administrator \/ SYSTEM<br><br>    .CHANGELOG<br>    [1.3.1] 2026-03-12 - FIX: bij bestaande TPM-protector eerst<br>                         'manage-bde -protectors -enable' en daarna 'manage-bde -on'<br>                         (anders start encryptie niet ondanks aanwezige protectors)<br>    [1.3]   2026-03-12 - Duplication-safe enable (manage-bde fallback), Hard Block bij TPM not-ready,<br>                         verbeterde foutbranching (0x80310031\/0x8031004E), logging aangescherpt<br>    [1.2]   2026-03-12 - Correct parameterset (-TpmProtector), pending reboot guard, extra logging<br>    [1.1]   2026-03-09 - Opschoning, robuustere logging, betere foutafhandeling<br>    [1.0]   2025-06-21 - Eerste versie<br>#><br><br>#region Script metadata<br>$ScriptAuthor        = \"Vincent van Unen\"<br>$ScriptVersion       = \"1.3.1\"<br>$ScriptChangeDate    = \"2026-03-12\"<br>$ScriptCurrentUser   = $env:UserName<br>$ScriptRunningDevice = $env:COMPUTERNAME<br>$CurrentDate         = Get-Date -Format \"yyyy-MM-dd\"<br>$LogName             = \"SCA_CheckenFix_BitLocker\"<br>#endregion Script metadata<br><br>#region Configuration<br>[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12<br><br>$MaximumFunctionCount = 16384<br>$MaximumVariableCount = 16384<br><br>$TempDirs = @(\"C:\\Temp\",\"C:\\Tmp\",\"C:\\Log\")<br><br>$LogDirectory    = \"C:\\Log\"<br>$LogFile         = Join-Path $LogDirectory \"$LogName $CurrentDate.log\"<br>$TranscriptFile  = Join-Path $LogDirectory \"${CurrentDate}_${LogName}_Transcript.log\"<br>$IntuneLogFolder = \"C:\\ProgramData\\Microsoft\\IntuneManagementExtension\\Logs\"<br><br>$TranscriptStarted = $false<br>$ExitCode = 1<br><br>$OSDrive = $env:SystemDrive<br>#endregion Configuration<br><br>#region Functions<br>function Write-Log {<br>    [CmdletBinding()]<br>    param (<br>        [ValidateSet(\"INFO\",\"WARN\",\"ERROR\",\"FATAL\",\"DEBUG\")]<br>        [string]$Level = \"INFO\",<br>        [Parameter(Mandatory = $true)][string]$Message,<br>        [string]$Path = $LogFile<br>    )<br>    try {<br>        $timestamp = (Get-Date).ToString(\"yyyy-MM-dd HH:mm:ss.fff\")<br>        Add-Content -Path $Path -Value \"[$timestamp] [$Level] $Message\" -ErrorAction Stop<br>    } catch {<br>        Write-Warning \"Logging mislukt: $($_.Exception.Message)\"<br>    }<br>}<br><br>function Write-ConsoleAndLog {<br>    param (<br>        [Parameter(Mandatory = $true)][string]$Message,<br>        [ValidateSet(\"INFO\",\"WARN\",\"ERROR\",\"FATAL\",\"DEBUG\")]<br>        [string]$Level = \"INFO\"<br>    )<br>    if (-not $Silent) { Write-Output $Message }<br>    Write-Log -Level $Level -Message $Message<br>}<br><br>function Test-IsAdministrator {<br>    try {<br>        if ($env:USERNAME -eq 'SYSTEM') { return $true }<br>        $currentIdentity = [Security.Principal.WindowsIdentity]::GetCurrent()<br>        $principal = New-Object Security.Principal.WindowsPrincipal($currentIdentity)<br>        return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)<br>    } catch { return $false }<br>}<br><br>function Get-PublicIP {<br>    try { return (Invoke-RestMethod -Uri \"https:\/\/ifconfig.me\/ip\" -TimeoutSec 10 -ErrorAction Stop).Trim() }<br>    catch { return \"Onbekend\" }<br>}<br><br>function Get-PrivateIP {<br>    try {<br>        $ip = Get-NetIPAddress -AddressFamily IPv4 -ErrorAction Stop |<br>            Where-Object { $_.IPAddress -notlike \"169.254.*\" -and $_.IPAddress -ne \"127.0.0.1\" -and $_.PrefixOrigin -ne \"WellKnown\" } |<br>            Sort-Object InterfaceMetric | Select-Object -First 1 -ExpandProperty IPAddress<br>        if ([string]::IsNullOrWhiteSpace($ip)) { return \"Onbekend\" }<br>        return $ip<br>    } catch { return \"Onbekend\" }<br>}<br><br>function Test-PendingReboot {<br>    &lt;# Detecteert veelvoorkomende reboot-triggers (CBS, pendmoves, WU, naamwijziging) #><br>    try {<br>        if (Get-ItemProperty -Path 'HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\RebootPending' -ErrorAction SilentlyContinue) { return $true }<br>        $pn = Get-ItemProperty -Path 'HKLM:\\SYSTEM\\CurrentControlSet\\Control\\Session Manager' -Name 'PendingFileRenameOperations' -ErrorAction SilentlyContinue<br>        if ($pn -and $pn.PendingFileRenameOperations) { return $true }<br>        if (Get-ItemProperty -Path 'HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update\\RebootRequired' -ErrorAction SilentlyContinue) { return $true }<br>        $nm = Get-ItemProperty -Path 'HKLM:\\SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ComputerName' -ErrorAction SilentlyContinue<br>        $an = Get-ItemProperty -Path 'HKLM:\\SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ActiveComputerName' -ErrorAction SilentlyContinue<br>        if ($nm -and $an -and $nm.ComputerName -ne $an.ComputerName) { return $true }<br>        return $false<br>    } catch {<br>        Write-ConsoleAndLog -Level \"WARN\" -Message \"Pending reboot check mislukt: $($_.Exception.Message)\"<br>        return $false<br>    }<br>}<br>#endregion Functions<br><br>#region Preparation<br>foreach ($dir in $TempDirs) {<br>    if (-not (Test-Path -Path $dir)) { New-Item -ItemType Directory -Path $dir -Force | Out-Null }<br>}<br><br>Write-Log -Message \"Current Date = $CurrentDate\"<br>Write-Log -Message \"Script Author = $ScriptAuthor\"<br>Write-Log -Message \"Script Version = $ScriptVersion\"<br>Write-Log -Message \"Script ChangeDate = $ScriptChangeDate\"<br>Write-Log -Message \"Current User Running this script = $ScriptCurrentUser\"<br>Write-Log -Message \"Current Device Running this script = $ScriptRunningDevice\"<br>Write-Log -Message \"Current Public IP = $(Get-PublicIP)\"<br>Write-Log -Message \"Current Private IP = $(Get-PrivateIP)\"<br><br>try {<br>    Start-Transcript -Path $TranscriptFile -Force -ErrorAction Stop | Out-Null<br>    $TranscriptStarted = $true<br>    Write-Log -Message \"Transcript gestart: $TranscriptFile\"<br>} catch {<br>    Write-Log -Level \"WARN\" -Message \"Transcript kon niet worden gestart: $($_.Exception.Message)\"<br>}<br>#endregion Preparation<br><br>try {<br>    Write-ConsoleAndLog -Message \"Start controle op TPM en BitLocker.\"<br><br>    if (-not (Test-IsAdministrator)) { throw \"Dit script moet worden uitgevoerd als administrator of SYSTEM.\" }<br><br>    # Pending reboot guard \u2013 voorkomt FVE_E_REBOOT_REQUIRED (0x8031004E)<br>    if (Test-PendingReboot) {<br>        throw \"Herstart vereist voordat BitLocker kan worden ingeschakeld (FVE_E_REBOOT_REQUIRED, 0x8031004E).\"<br>    }<br><br>    # Cmdlets beschikbaar?<br>    if (-not (Get-Command Get-BitLockerVolume -ErrorAction SilentlyContinue)) {<br>        throw \"De BitLocker PowerShell-cmdlets zijn niet beschikbaar op dit systeem.\"<br>    }<br>    if (-not (Get-Command Get-Tpm -ErrorAction SilentlyContinue)) {<br>        throw \"De TPM PowerShell-cmdlets zijn niet beschikbaar op dit systeem.\"<br>    }<br><br>    $BitLockerVolume = Get-BitLockerVolume -MountPoint $OSDrive -ErrorAction Stop<br>    $TPM = Get-Tpm -ErrorAction Stop<br><br>    Write-ConsoleAndLog -Message \"Controle van TPM en BitLocker gestart op $OSDrive.\"<br><br>    # Hard Block: TPM aanwezig maar niet gereed \u2192 mogelijke TPM reset nodig (runbook)<br>    if ($TPM.TpmPresent -and -not $TPM.TpmReady) {<br>        Write-ConsoleAndLog -Level \"ERROR\" -Message \"HARD BLOCK: TPM is niet gereed. Remediation stopt. Volg het runbook 'TPM reset + BitLocker herstel'.\"<br>        $ExitCode = 1<br>        exit $ExitCode<br>    }<br><br>    if (-not $TPM.TpmPresent)    { throw \"TPM is niet aanwezig. BitLocker kan niet met TPM worden geconfigureerd.\" }<br>    if (-not $TPM.TpmEnabled)    { throw \"TPM is uitgeschakeld. Schakel TPM in BIOS\/UEFI in.\" }<br>    if (-not $TPM.TpmActivated)  { throw \"TPM is niet geactiveerd. Activeer TPM in BIOS\/UEFI.\" }<br><br>    # Protectors inventariseren<br>    $RecoveryProtectors = $BitLockerVolume.KeyProtector | Where-Object { $_.KeyProtectorType -eq \"RecoveryPassword\" }<br>    $TpmProtectors      = $BitLockerVolume.KeyProtector | Where-Object { $_.KeyProtectorType -eq \"Tpm\" }<br>    $HasTpmProtector    = [bool]$TpmProtectors<br><br>    # Recovery Password protector verplicht (voor backup naar Entra ID)<br>    if (-not $RecoveryProtectors) {<br>        Write-ConsoleAndLog -Message \"Recovery password protector ontbreekt. Deze wordt toegevoegd.\"<br>        Add-BitLockerKeyProtector -MountPoint $OSDrive -RecoveryPasswordProtector -ErrorAction Stop | Out-Null<br>        $BitLockerVolume   = Get-BitLockerVolume -MountPoint $OSDrive -ErrorAction Stop<br>        $RecoveryProtectors = $BitLockerVolume.KeyProtector | Where-Object { $_.KeyProtectorType -eq \"RecoveryPassword\" }<br>    }<br><br>    # TPM protector toevoegen als nog niet aanwezig<br>    if (-not $HasTpmProtector) {<br>        Write-ConsoleAndLog -Message \"TPM protector ontbreekt. Deze wordt toegevoegd.\"<br>        Add-BitLockerKeyProtector -MountPoint $OSDrive -TpmProtector -ErrorAction Stop | Out-Null<br>        $BitLockerVolume = Get-BitLockerVolume -MountPoint $OSDrive -ErrorAction Stop<br>        $TpmProtectors   = $BitLockerVolume.KeyProtector | Where-Object { $_.KeyProtectorType -eq \"Tpm\" }<br>        $HasTpmProtector = [bool]$TpmProtectors<br>    }<br><br>    # BitLocker inschakelen (duplication-safe, met enable-protectors bij bestaande TPM)<br>    if ($BitLockerVolume.VolumeStatus -eq \"FullyDecrypted\" -or $BitLockerVolume.ProtectionStatus -eq \"Off\") {<br>        Write-ConsoleAndLog -Message \"BitLocker is niet actief. Inschakelen wordt gestart.\"<br><br>        # Protectors v\u00f3\u00f3r enable (debug)<br>        $preKP = $BitLockerVolume.KeyProtector | Select-Object KeyProtectorId, KeyProtectorType<br>        Write-ConsoleAndLog -Level \"DEBUG\" -Message (\"Protectors v\u00f3\u00f3r Enable-BitLocker:`n\" + ($preKP | Out-String))<br><br>        try {<br>            if ($HasTpmProtector) {<br>                # TPM protector bestaat al \u2192 eerst protectors activeren, dan encryptie starten<br>                $manageBde = (Get-Command manage-bde.exe -ErrorAction SilentlyContinue)<br>                if ($manageBde) {<br>                    Write-ConsoleAndLog -Message \"TPM\u2011protector aanwezig \u2192 protectors activeren en encryptie starten via manage-bde.\"<br>                    &amp; $manageBde.Source -protectors -enable $OSDrive | Out-Null<br>                    &amp; $manageBde.Source -on $OSDrive -method xts_aes256 -usedspaceonly -skiphardwaretest | Out-Null<br>                } else {<br>                    # Fallback: pure PowerShell (zonder extra protector en zonder -SkipHardwareTest om AmbiguousParameterSet te vermijden)<br>                    Write-ConsoleAndLog -Level \"WARN\" -Message \"manage-bde niet gevonden. Fallback naar PowerShell\u2011enable zonder extra protector (reboot kan vereist zijn).\"<br>                    Enable-BitLocker -MountPoint $OSDrive -EncryptionMethod XtsAes256 -UsedSpaceOnly -ErrorAction Stop | Out-Null<br>                }<br>            }<br>            else {<br>                # TPM protector zojuist toegevoegd \u2192 correct parameterset met -TpmProtector (OS\u2011volume + SkipHardwareTest)<br>                Write-ConsoleAndLog -Message \"TPM\u2011protector toegevoegd \u2192 Enable\u2011BitLocker via -TpmProtector (SkipHardwareTest).\"<br>                Enable-BitLocker `<br>                    -MountPoint $OSDrive `<br>                    -TpmProtector `<br>                    -EncryptionMethod XtsAes256 `<br>                    -UsedSpaceOnly `<br>                    -SkipHardwareTest `<br>                    -ErrorAction Stop | Out-Null<br>            }<br><br>            Write-ConsoleAndLog -Message \"Enable\u2011fase afgerond; status ophalen\u2026\"<br>            Start-Sleep -Seconds 10<br>            $BitLockerVolume = Get-BitLockerVolume -MountPoint $OSDrive -ErrorAction Stop<br><br>            # Protectors n\u00e1 enable<br>            $postKP = $BitLockerVolume.KeyProtector | Select-Object KeyProtectorId, KeyProtectorType<br>            Write-ConsoleAndLog -Level \"DEBUG\" -Message (\"Protectors n\u00e1 Enable\u2011BitLocker:`n\" + ($postKP | Out-String))<br>            Write-ConsoleAndLog -Message (\"Huidige status: VolumeStatus={0}, ProtectionStatus={1}, EncryptionPercent={2}\" -f `<br>                                         $BitLockerVolume.VolumeStatus, $BitLockerVolume.ProtectionStatus, $BitLockerVolume.EncryptionPercentage)<br>        }<br>        catch {<br>            $global:LastBitLockerError = $_.Exception.Message<br>            $msg = $global:LastBitLockerError<br><br>            if ($msg -match '0x80310031' -or $msg -match 'FVE_E_PROTECTOR_EXISTS') {<br>                Write-ConsoleAndLog -Level \"ERROR\" -Message \"0x80310031 (FVE_E_PROTECTOR_EXISTS): er bestaat al een protector van dit type. Gebruik de duplication-safe flow (protectors enable + manage-bde -on).\"<br>            }<br>            elseif ($msg -match '0x8031004E' -or $msg -match 'FVE_E_REBOOT_REQUIRED') {<br>                Write-ConsoleAndLog -Level \"ERROR\" -Message \"0x8031004E (FVE_E_REBOOT_REQUIRED): herstart vereist voordat BitLocker kan doorgaan.\"<br>            }<br>            else {<br>                Write-ConsoleAndLog -Level \"ERROR\" -Message \"Enable\u2011BitLocker mislukt: $msg\"<br>            }<br>            throw<br>        }<br>    }<br>    else {<br>        Write-ConsoleAndLog -Message \"BitLocker is al actief of de versleuteling is al gestart.\"<br>    }<br><br>    # Valideer RecoveryPassword protectors<br>    $BitLockerVolume   = Get-BitLockerVolume -MountPoint $OSDrive -ErrorAction Stop<br>    $RecoveryProtectors = $BitLockerVolume.KeyProtector | Where-Object { $_.KeyProtectorType -eq \"RecoveryPassword\" }<br>    if (-not $RecoveryProtectors) { throw \"Recovery password protector ontbreekt nog steeds na herstelpoging.\" }<br><br>    # Backup recovery keys naar Entra ID (indien cmdlet beschikbaar)<br>    if (Get-Command BackupToAAD-BitLockerKeyProtector -ErrorAction SilentlyContinue) {<br>        foreach ($Protector in $RecoveryProtectors) {<br>            try {<br>                BackupToAAD-BitLockerKeyProtector -MountPoint $OSDrive -KeyProtectorId $Protector.KeyProtectorId -ErrorAction Stop<br>                Write-ConsoleAndLog -Message \"Recovery key succesvol geback-upt naar Entra ID.\"<br>            } catch {<br>                Write-ConsoleAndLog -Level \"WARN\" -Message \"Backup naar Entra ID is niet gelukt: $($_.Exception.Message)\"<br>            }<br>        }<br>    } else {<br>        Write-ConsoleAndLog -Level \"WARN\" -Message \"Cmdlet BackupToAAD-BitLockerKeyProtector is niet beschikbaar. Backup naar Entra ID is overgeslagen.\"<br>    }<br><br>    # Eindstatus<br>    $FinalStatus = Get-BitLockerVolume -MountPoint $OSDrive -ErrorAction Stop<br><br>    Write-ConsoleAndLog -Message \"Eindstatus:\"<br>    Write-ConsoleAndLog -Message \"VolumeStatus      : $($FinalStatus.VolumeStatus)\"<br>    Write-ConsoleAndLog -Message \"ProtectionStatus  : $($FinalStatus.ProtectionStatus)\"<br>    Write-ConsoleAndLog -Message \"EncryptionPercent : $($FinalStatus.EncryptionPercentage)\"<br><br>    if ($FinalStatus.ProtectionStatus -eq \"On\" -or $FinalStatus.VolumeStatus -in @(\"EncryptionInProgress\", \"FullyEncrypted\")) {<br>        Write-ConsoleAndLog -Message \"BitLocker-remediation is succesvol gestart of voltooid.\"<br>        $ExitCode = 0<br>    } else {<br>        throw \"BitLocker-remediation is niet succesvol.\"<br>    }<br>}<br>catch {<br>    Write-ConsoleAndLog -Level \"ERROR\" -Message \"Remediation mislukt: $($_.Exception.Message)\"<br>    $ExitCode = 1<br>}<br>finally {<br>    if ($TranscriptStarted) {<br>        try {<br>            Stop-Transcript | Out-Null<br>            Write-Log -Message \"Transcript gestopt.\"<br>        } catch {<br>            Write-Log -Level \"WARN\" -Message \"Stop-Transcript mislukt: $($_.Exception.Message)\"<br>        }<br>    }<br><br>    try {<br>        if (Test-Path -Path $IntuneLogFolder) {<br>            Copy-Item -Path $TranscriptFile -Destination $IntuneLogFolder -Force -ErrorAction Stop<br>            Write-Log -Message \"Transcript gekopieerd naar $IntuneLogFolder\"<br>        } else {<br>            Write-Log -Level \"WARN\" -Message \"Intune-logmap bestaat niet: $IntuneLogFolder\"<br>        }<br>    } catch {<br>        Write-Log -Level \"WARN\" -Message \"Kopi\u00ebren van transcript is mislukt: $($_.Exception.Message)\"<br>    }<br><br>    exit $ExitCode<br>}<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\ude80 Samenvatting<\/h2>\n\n\n\n<p>Met dit script zorg je ervoor dat:<\/p>\n\n\n\n<p>\u2705 BitLocker automatisch wordt ingeschakeld<br>\u2705 TPM wordt gecontroleerd<br>\u2705 Recovery keys automatisch worden aangemaakt<br>\u2705 Recovery keys veilig in <strong>Entra ID<\/strong> worden opgeslagen<br>\u2705 Uitgebreide logging beschikbaar is<\/p>\n\n\n\n<p>Een krachtige manier om <strong>endpoint-beveiliging automatisch af te dwingen binnen je organisatie<\/strong>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Beveiliging van endpoints is tegenwoordig geen luxe meer, maar een noodzaak. Gelukkig helpt Microsoft BitLocker daarbij door schijven<\/p>\n","protected":false},"author":2,"featured_media":111,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,6],"tags":[],"class_list":["post-110","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-intune","category-powershell"],"_links":{"self":[{"href":"https:\/\/unen.nl\/index.php?rest_route=\/wp\/v2\/posts\/110","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unen.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unen.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unen.nl\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/unen.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=110"}],"version-history":[{"count":2,"href":"https:\/\/unen.nl\/index.php?rest_route=\/wp\/v2\/posts\/110\/revisions"}],"predecessor-version":[{"id":119,"href":"https:\/\/unen.nl\/index.php?rest_route=\/wp\/v2\/posts\/110\/revisions\/119"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unen.nl\/index.php?rest_route=\/wp\/v2\/media\/111"}],"wp:attachment":[{"href":"https:\/\/unen.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unen.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unen.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}