Windows PowerShell 脚本:启用 BitLocker 加密
以下是一个示例的 PowerShell 脚本,用于在 Windows 上启用 BitLocker:\n\npowershell\n# 检查是否支持 BitLocker\n$drive = 'C:'\nif ((Get-WmiObject -Namespace 'ROOT\CIMv2\Security\MicrosoftVolumeEncryption' -Query 'SELECT * FROM Win32_EncryptableVolume WHERE DriveLetter = '$drive'').ProtectionStatus -ne 0) {\n Write-Host '该驱动器已启用 BitLocker。'\n exit\n}\n\n# 检查是否存在 TPM 芯片\n$tpmStatus = Get-WmiObject -Namespace 'ROOT\CIMv2\Security\MicrosoftTpm' -Class Win32_Tpm | Select-Object -ExpandProperty SpecVersion\nif ($tpmStatus -eq $null) {\n Write-Host '该计算机没有 TPM 芯片。无法启用 BitLocker。'\n exit\n}\n\n# 请求 BitLocker 密码\n$password = Read-Host -Prompt '请输入 BitLocker 密码' -AsSecureString\n\n# 启用 BitLocker\n$encryptionMethod = 'aes256'\n$securePassword = ConvertTo-SecureString -String $password -AsPlainText -Force\n$protector = Get-WmiObject -Namespace 'ROOT\CIMv2\Security\MicrosoftVolumeEncryption' -Query 'SELECT * FROM Win32_EncryptableVolume WHERE DriveLetter = '$drive'' | Get-BitLockerVolume\n$protector.ProtectWithPassword($securePassword, $encryptionMethod)\n\nWrite-Host 'BitLocker 已成功启用!'\n\n\n请注意,这个脚本假设要启用 BitLocker 的驱动器为 C:驱动器。如果要启用其他驱动器,请将$drive变量设置为相应的驱动器字母。
原文地址: https://www.cveoy.top/t/topic/p3Fx 著作权归作者所有。请勿转载和采集!