PowerShell ile BitLocker Şifreleme Yönetimi

Kurumsal ortamlarda disk şifreleme artık bir seçenek değil, zorunluluk haline geldi. Özellikle dizüstü bilgisayarların veya taşınabilir depolama cihazlarının kaybolması durumunda, BitLocker olmadan veri ihlali riski son derece yüksek. Peki bu şifreleme sürecini onlarca, hatta yüzlerce makineye manuel olarak uygulamak mı? Hayır, teşekkürler. PowerShell tam da bu noktada devreye giriyor ve BitLocker yönetimini merkezi, tekrarlanabilir ve denetlenebilir hale getiriyor.

BitLocker ve PowerShell: Neden Bu İkili?

Windows’ta BitLocker yönetimi için iki temel araç var: GUI üzerinden Denetim Masası ve komut satırı araçları. manage-bde eski nesil komut satırı aracı iken, PowerShell’in BitLocker modülü çok daha güçlü ve modern scripting ihtiyaçlarına cevap veriyor. Özellikle Windows Server 2012 R2 ve sonrası ile Windows 8.1+ sistemlerde bu modül yerleşik olarak geliyor.

Öncelikle modülün mevcut olup olmadığını kontrol edelim:

Get-Module -ListAvailable -Name BitLocker
Import-Module BitLocker

Eğer modül yüklü değilse, özelliği aktif etmek gerekiyor:

Add-WindowsFeature BitLocker -IncludeAllSubFeature -IncludeManagementTools -Restart

Server Core kurulumlarında bu adım sıkça gerekiyor. -Restart parametresini kullanmak istemiyorsanız çıkarıp manuel restart atabilirsiniz ama TPM ile ilgili değişiklikler genellikle restart olmadan tam olarak uygulanmıyor.

TPM Durumunu Kontrol Etmek

BitLocker şifrelemesi başlatmadan önce TPM (Trusted Platform Module) durumunu anlamak kritik. TPM olmayan sistemlerde BitLocker çalışır ama anahtar yönetimi farklılaşır.

# TPM modülü bilgilerini getir
Get-Tpm

# Daha detaylı TPM bilgisi
$tpm = Get-Tpm
Write-Host "TPM Mevcut: $($tpm.TpmPresent)"
Write-Host "TPM Aktif: $($tpm.TpmEnabled)"
Write-Host "TPM Sahiplenilmiş: $($tpm.TpmOwned)"
Write-Host "TPM Hazır: $($tpm.TpmReady)"

Çıktıda TpmReady: True görüyorsanız hazırsınız demektir. TpmReady: False ise BIOS/UEFI ayarlarından TPM’i aktif etmeniz gerekiyor. Bunu uzaktan yapamazsınız, fiziksel erişim şart.

Sürücü Şifrelemeyi Başlatmak

En basit senaryoyla başlayalım: C: sürücüsünü TPM kullanarak şifrele.

# Temel BitLocker aktivasyonu - TPM ile
Enable-BitLocker -MountPoint "C:" -EncryptionMethod XtsAes256 -TpmProtector

# Recovery anahtarını da ekleyelim (şiddetle tavsiye edilir)
Add-BitLockerKeyProtector -MountPoint "C:" -RecoveryPasswordProtector

Burada -EncryptionMethod parametresi önemli. Seçenekler şunlar:

  • AES128: 128-bit AES, eski sistemlerle uyumlu
  • AES256: 256-bit AES, daha güçlü şifreleme
  • XtsAes128: XTS modunda 128-bit, Windows 10/Server 2016+
  • XtsAes256: XTS modunda 256-bit, mümkünse bu kullanılmalı

XTS modu, disk şifreleme için özel tasarlanmış ve sektör bazlı saldırılara karşı daha dirençli. Kurumsal ortamlarda XtsAes256 standardı benimseyin.

Add-BitLockerKeyProtector ile eklenen recovery password, 48 haneli bir numerik anahtar oluşturuyor. Bu anahtarı kaydetmeden sistemi yeniden başlatmayın.

Recovery Anahtarlarını Yönetmek

Recovery anahtarları BitLocker yönetiminin en kritik parçası. Kaybedilen bir anahtar, şifreli diske erişim kaybı demek.

# Mevcut key protector'ları listele
$bitlockerInfo = Get-BitLockerVolume -MountPoint "C:"
$bitlockerInfo.KeyProtector

# Recovery anahtarını dosyaya yedekle
$mountPoint = "C:"
$keyProtectors = (Get-BitLockerVolume -MountPoint $mountPoint).KeyProtector
foreach ($protector in $keyProtectors) {
    if ($protector.KeyProtectorType -eq "RecoveryPassword") {
        $recoveryKey = $protector.RecoveryPassword
        $keyId = $protector.KeyProtectorId
        $output = "KeyID: $keyId`nRecovery Key: $recoveryKey"
        $output | Out-File -FilePath "\fileserverbitlocker-keys$env:COMPUTERNAME-recovery.txt" -Append
        Write-Host "Recovery anahtari kaydedildi: $keyId"
    }
}

Daha profesyonel bir yaklaşım için recovery anahtarlarını Active Directory’e yedeklemek gerekiyor:

# Active Directory'e recovery password yedekle
$volumeInfo = Get-BitLockerVolume -MountPoint "C:"
$recoveryProtector = $volumeInfo.KeyProtector | Where-Object {$_.KeyProtectorType -eq "RecoveryPassword"}

if ($recoveryProtector) {
    Backup-BitLockerKeyProtector -MountPoint "C:" -KeyProtectorId $recoveryProtector.KeyProtectorId
    Write-Host "Recovery anahtari Active Directory'e yedeklendi."
} else {
    Write-Warning "Recovery password protector bulunamadi!"
}

Bu komut çalışabilmesi için domain ortamında olmanız ve Group Policy ile AD BitLocker yedeklemenin aktif edilmiş olması gerekiyor. Computer Configuration > Administrative Templates > Windows Components > BitLocker Drive Encryption altından bu ayarı yapabilirsiniz.

Şifreleme Durumunu İzlemek

Şifreleme işlemi başladıktan sonra ilerlemeyi takip etmek için:

# Anlık durum kontrolü
Get-BitLockerVolume -MountPoint "C:" | Select-Object MountPoint, VolumeStatus, EncryptionPercentage, ProtectionStatus

# Tüm sürücüleri kontrol et
Get-BitLockerVolume | Select-Object MountPoint, VolumeStatus, EncryptionPercentage, EncryptionMethod, ProtectionStatus

# Şifreleme tamamlanana kadar bekle ve rapor et
do {
    $volume = Get-BitLockerVolume -MountPoint "C:"
    $percent = $volume.EncryptionPercentage
    Write-Host "$(Get-Date -Format 'HH:mm:ss') - Sifreleme durumu: %$percent - $($volume.VolumeStatus)"
    Start-Sleep -Seconds 30
} while ($volume.VolumeStatus -eq "EncryptionInProgress")

Write-Host "Sifreleme tamamlandi! Son durum: $($volume.VolumeStatus)"

VolumeStatus değerleri şu anlamlara geliyor:

  • FullyEncrypted: Tam şifreli, koruma aktif
  • FullyDecrypted: Şifre yok
  • EncryptionInProgress: Şifreleme devam ediyor
  • DecryptionInProgress: Şifre çözme devam ediyor
  • EncryptionSuspended: Şifreleme askıya alındı

ProtectionStatus: On veya Off değeri alır. Dikkat: VolumeStatus FullyEncrypted olsa bile ProtectionStatus Off olabilir. Bu genellikle update veya BIOS değişikliği sonrası suspend durumunu gösterir.

Toplu Dağıtım Senaryosu

Gerçek dünyada 50 makineye BitLocker uygulamak gerekiyor diyelim. Remote PowerShell ile bunu merkezi olarak yapabilirsiniz:

# Hedef bilgisayar listesi
$computers = Get-Content -Path "C:Scriptscomputers.txt"

$credential = Get-Credential -Message "Yonetici kimlik bilgilerini girin"

foreach ($computer in $computers) {
    Write-Host "Islem baslatiyor: $computer" -ForegroundColor Cyan
    
    try {
        $session = New-PSSession -ComputerName $computer -Credential $credential -ErrorAction Stop
        
        Invoke-Command -Session $session -ScriptBlock {
            # TPM kontrolu
            $tpm = Get-Tpm
            if (-not $tpm.TpmReady) {
                Write-Warning "$env:COMPUTERNAME - TPM hazir degil, atlaniyor."
                return
            }
            
            # Zaten sifreliyse atla
            $blVolume = Get-BitLockerVolume -MountPoint "C:"
            if ($blVolume.VolumeStatus -eq "FullyEncrypted") {
                Write-Host "$env:COMPUTERNAME - Zaten sifrelenmis, atlaniyor."
                return
            }
            
            # Sifrele
            Enable-BitLocker -MountPoint "C:" -EncryptionMethod XtsAes256 -TpmProtector -UsedSpaceOnly
            Add-BitLockerKeyProtector -MountPoint "C:" -RecoveryPasswordProtector
            
            # AD'ye yedekle
            $protector = (Get-BitLockerVolume -MountPoint "C:").KeyProtector | 
                         Where-Object {$_.KeyProtectorType -eq "RecoveryPassword"}
            if ($protector) {
                Backup-BitLockerKeyProtector -MountPoint "C:" -KeyProtectorId $protector.KeyProtectorId
            }
            
            Write-Host "$env:COMPUTERNAME - BitLocker baslatildi." -ForegroundColor Green
        }
        
        Remove-PSSession $session
    }
    catch {
        Write-Error "$computer - Hata: $_"
    }
}

Burada -UsedSpaceOnly parametresine dikkat edin. Bu parametre sadece kullanılan alanı şifreler, tüm diski değil. Yeni veya az kullanılmış disklerde şifreleme süresini dramatik biçimde kısaltır. Güvenlik açısından zaten yazılan veriler anında şifreleneceği için production ortamlarda kabul edilebilir bir trade-off.

Veri Sürücülerini ve USB Disklerini Yönetmek

İşletim sistemi dışındaki sürücüler için yaklaşım biraz farklı. Parola korumalı şifreleme genellikle veri sürücüleri için kullanılır:

# Veri surucusu sifreleme - parola ile
$securePassword = ConvertTo-SecureString "KurumSifresi2024!" -AsPlainText -Force
Enable-BitLocker -MountPoint "D:" -EncryptionMethod XtsAes256 -Password $securePassword -PasswordProtector

# USB disk sifreleme (BitLocker To Go)
$usbDrive = "E:"
Enable-BitLocker -MountPoint $usbDrive -EncryptionMethod AES256 -Password $securePassword -PasswordProtector

# Recovery anahtarini dosyaya kaydet
$keyProtector = (Get-BitLockerVolume -MountPoint $usbDrive).KeyProtector | 
                Where-Object {$_.KeyProtectorType -eq "RecoveryPassword"}
Add-BitLockerKeyProtector -MountPoint $usbDrive -RecoveryPasswordProtector

$recoveryPassword = (Get-BitLockerVolume -MountPoint $usbDrive).KeyProtector | 
                    Where-Object {$_.KeyProtectorType -eq "RecoveryPassword"} | 
                    Select-Object -ExpandProperty RecoveryPassword

Write-Host "USB Recovery Anahtari: $recoveryPassword" -ForegroundColor Yellow

Kurumsal USB politikası oluşturuyorsanız Group Policy ile birleştirin: Computer Configuration > Windows Settings > Security Settings > BitLocker Drive Encryption > Removable Data Drives altından USB’lerin şifresiz kullanımını kısıtlayabilirsiniz.

BitLocker’ı Geçici Askıya Almak

Windows Update, BIOS güncellemesi veya disk klonlama gibi durumlarda BitLocker’ı geçici olarak suspend etmek gerekebilir:

# Bir sonraki yeniden baslatmaya kadar askiya al
Suspend-BitLocker -MountPoint "C:" -RebootCount 1

# Birden fazla yeniden baslatma icin (orn. firmware guncelleme)
Suspend-BitLocker -MountPoint "C:" -RebootCount 2

# Manuel olarak tekrar aktif et
Resume-BitLocker -MountPoint "C:"

# Mevcut durumu kontrol et
$vol = Get-BitLockerVolume -MountPoint "C:"
Write-Host "Koruma Durumu: $($vol.ProtectionStatus)"
Write-Host "Kilitleme Durumu: $($vol.LockStatus)"

RebootCount 0 kullanırsanız BitLocker süresiz askıda kalır, siz tekrar Resume-BitLocker çalıştırana kadar. BIOS güncellemesi yaparken bu kullanım pratikte daha sık tercih ediliyor çünkü kaç restart olacağını önceden bilmek zor.

Raporlama ve Denetim Scripti

Yöneticilerin en çok ihtiyaç duyduğu şeylerden biri mevcut ortamın BitLocker durumu raporu. Bunu bir script haline getirelim:

# BitLocker Durum Raporu
$reportPath = "C:ReportsBitLocker-Report-$(Get-Date -Format 'yyyyMMdd-HHmm').csv"
$computers = (Get-ADComputer -Filter {OperatingSystem -like "*Windows*"} -Properties Name).Name
$report = @()

foreach ($computer in $computers) {
    $status = [PSCustomObject]@{
        ComputerName    = $computer
        LastChecked     = Get-Date -Format "yyyy-MM-dd HH:mm"
        Reachable       = $false
        OSVolume        = "Bilinmiyor"
        EncryptionPct   = 0
        ProtectionStatus = "Bilinmiyor"
        EncryptionMethod = "Bilinmiyor"
        TPMReady        = "Bilinmiyor"
        RecoveryInAD    = "Bilinmiyor"
        Notes           = ""
    }
    
    try {
        $session = New-PSSession -ComputerName $computer -ErrorAction Stop
        $status.Reachable = $true
        
        $result = Invoke-Command -Session $session -ScriptBlock {
            $vol = Get-BitLockerVolume -MountPoint "C:" -ErrorAction SilentlyContinue
            $tpm = Get-Tpm -ErrorAction SilentlyContinue
            $hasRecovery = ($vol.KeyProtector | Where-Object {$_.KeyProtectorType -eq "RecoveryPassword"}) -ne $null
            
            [PSCustomObject]@{
                VolumeStatus     = $vol.VolumeStatus
                EncPct           = $vol.EncryptionPercentage
                ProtStatus       = $vol.ProtectionStatus
                EncMethod        = $vol.EncryptionMethod
                TpmReady         = $tpm.TpmReady
                HasRecovery      = $hasRecovery
            }
        }
        
        $status.OSVolume        = $result.VolumeStatus
        $status.EncryptionPct   = $result.EncPct
        $status.ProtectionStatus = $result.ProtStatus
        $status.EncryptionMethod = $result.EncMethod
        $status.TPMReady        = $result.TpmReady
        $status.RecoveryInAD    = $result.HasRecovery
        
        Remove-PSSession $session
    }
    catch {
        $status.Notes = "Baglanti hatasi: $_"
    }
    
    $report += $status
    Write-Host "Kontrol edildi: $computer - $($status.OSVolume)" -ForegroundColor $(
        if ($status.OSVolume -eq "FullyEncrypted" -and $status.ProtectionStatus -eq "On") { "Green" }
        elseif ($status.OSVolume -eq "FullyDecrypted") { "Red" }
        else { "Yellow" }
    )
}

$report | Export-Csv -Path $reportPath -NoTypeInformation -Encoding UTF8
Write-Host "`nRapor kaydedildi: $reportPath" -ForegroundColor Cyan

# Ozet bilgi
$encrypted = ($report | Where-Object {$_.OSVolume -eq "FullyEncrypted"}).Count
$total = $report.Count
Write-Host "Toplam: $total makine, Sifrelenmis: $encrypted, Oran: %$([math]::Round($encrypted/$total*100, 1))"

Bu scripti Task Scheduler ile haftalık çalıştırıp management ekibine otomatik mail atabilirsiniz. Özellikle audit gereksinimleri olan ortamlarda (ISO 27001, PCI-DSS) bu tür raporlar çok işe yarıyor.

Sorun Giderme

Pratikte en sık karşılaşılan sorunlar ve çözümleri:

Secure Boot uyarısı: BitLocker bazı durumlarda Secure Boot politikası değişikliği algılar ve recovery key ister. Bu genellikle BIOS güncellemesi sonrası olur. Recovery key’i girdikten sonra sisteme girip Resume-BitLocker -MountPoint "C:" çalıştırın.

TPM locked out durumu: Çok fazla hatalı PIN denemesi TPM’i kilitler.

# TPM kilit durumunu kontrol et
$tpm = Get-Tpm
Write-Host "TPM Kilitli: $($tpm.TpmActivated)"
Write-Host "Kalan deneme sayisi: $($tpm.ManagedAuthLevel)"

# TPM kilidini coz (dikkatli kullanin)
Clear-Tpm

Clear-Tpm tehlikeli bir komut. TPM’i sıfırlar ve bazı durumlarda mevcut şifreli verilere erişimi kaybedebilirsiniz. Bunu yalnızca makineyi sıfırlayacaksanız veya uzman desteğiyle kullanın.

Key protector ekleme hatası: Bazen Enable-BitLocker sonrası hemen Add-BitLockerKeyProtector çalıştırınca “BitLocker is already turned on” hatası değil de protector ekleme hatası alabilirsiniz. Birkaç saniye bekleyip tekrar deneyin, TPM initialization tamamlanmamış olabilir.

# Mevcut key protector'lari temizleyip yeniden ekle
$vol = Get-BitLockerVolume -MountPoint "C:"
foreach ($protector in $vol.KeyProtector) {
    if ($protector.KeyProtectorType -eq "RecoveryPassword") {
        Remove-BitLockerKeyProtector -MountPoint "C:" -KeyProtectorId $protector.KeyProtectorId
    }
}
Add-BitLockerKeyProtector -MountPoint "C:" -RecoveryPasswordProtector

Network Unlock ile Domain Ortamı Entegrasyonu

Domain’e bağlı sistemlerde Network Unlock özelliği ile BitLocker korumalı makineler domain içindeyken otomatik unlock olabilir. Bunun için:

# Network Unlock protector ekle
Add-BitLockerKeyProtector -MountPoint "C:" -ADAccountOrGroupProtector -ADAccountOrGroup "DOMAINDomain Computers"

# Veya specific service account ile
Add-BitLockerKeyProtector -MountPoint "C:" -ADAccountOrGroupProtector -ADAccountOrGroup "DOMAINBitLockerService"

Network Unlock için WDS (Windows Deployment Services) sunucusunda ek konfigürasyon gerekiyor. DHCP ayarları ve PKI altyapısı da gerekli. Büyük kurumlarda bu yatırım değer, çünkü her sabah onlarca makinede PIN girmekten kurtarıyor kullanıcıları.

Sonuç

BitLocker yönetimini PowerShell ile otomatize etmek, özellikle 20 makinenin üzerindeki ortamlarda ciddi zaman ve emek tasarrufu sağlıyor. Konuştuğumuz temel noktalara bakacak olursak: TPM hazırlığı ve kontrol, XtsAes256 gibi güçlü şifreleme yöntemlerinin seçimi, recovery anahtarlarının Active Directory veya güvenli bir yedek noktasına kaydedilmesi ve toplu raporlama kritik adımlar.

Pratik olarak şunları öneririm: İlk deployment öncesi mutlaka bir pilot grup üzerinde test edin. Recovery anahtarı yedekleme prosedürünüzü netleştirin, çünkü bu adım atlandığında felaketle sonuçlanabilir. Suspend ve Resume operasyonlarını Windows Update görevlerinize entegre edin, bu sayede güncelleme sonrası BitLocker sorunlarının önüne geçersiniz. Son olarak, yukarıdaki raporlama scriptini scheduled task olarak kurgulayın ve compliance dashboard’unuza entegre edin.

Kurumunuzda SCCM/Intune kullanıyorsanız Microsoft’un MBAM (Microsoft BitLocker Administration and Monitoring) mirasını ve Intune’un modern BitLocker yönetimini de araştırmanızı tavsiye ederim. PowerShell bilginizle bu araçları da çok daha verimli kullanırsınız.

Yorum yapın