长期潜伏者第一次发帖。在很长一段时间没有使用 PowerShell 之后,我又开始涉足 PowerShell。我目前正在尝试制作一个启用 Bitlocker 的脚本,并将恢复密钥备份到桌面。我发现它可以很好地启用 Bitlocker,但是桌面上的恢复密钥没有显示恢复密钥?这是到目前为止的脚本:
#Test Registry paths before trying to modify
Test-Path HKLM:\SOFTWARE\Policies\Microsoft\FVE
#Change Registry keys to allow BitLocker without TPM and with additional authentication
#Check EnableBDEWithNoTPM value is correct, if not set it to be correct value.
Get-ItemProperty -Path hklm:\SOFTWARE\Policies\Microsoft\FVE -name "EnableBDEWithNoTPM"
if($val.EnableBDEWithNoTPM -ne 1)
{
Set-ItemProperty -Path hklm:\SOFTWARE\Policies\Microsoft\FVE -Name "EnableBDEWithNoTPM" -value 1
}
#Check UseAdvancedStartup value is correct, if not set it to be correct value.
Get-ItemProperty -Path hklm:\SOFTWARE\Policies\Microsoft\FVE -name "UseAdvancedStartup"
if($val.UseAdvancedStartup -ne 1)
{
Set-ItemProperty -Path hklm:\SOFTWARE\Policies\Microsoft\FVE -Name "UseAdvancedStartup" -value 1
}
#Check UseTPM value is correct, if not set it to be correct value.
Get-ItemProperty -Path hklm:\SOFTWARE\Policies\Microsoft\FVE -name "UseTPM"
if($val.UseTPM -ne 2)
{
Set-ItemProperty -Path hklm:\SOFTWARE\Policies\Microsoft\FVE -Name "UseTPM" -value 2
}
#Check UseTPMKey value is correct, if not set it to be correct value.
Get-ItemProperty -Path hklm:\SOFTWARE\Policies\Microsoft\FVE -name "UseTPMKey"
if($val.UseTPMKey -ne 2)
{
Set-ItemProperty -Path hklm:\SOFTWARE\Policies\Microsoft\FVE -Name "UseTPMKey" -value 2
}
#Check UseTPMKeyPIN value is correct, if not set it to be correct value.
Get-ItemProperty -Path hklm:\SOFTWARE\Policies\Microsoft\FVE -name "UseTPMKeyPIN"
if($val.UseTPMKeyPIN -ne 2)
{
Set-ItemProperty -Path hklm:\SOFTWARE\Policies\Microsoft\FVE -Name "UseTPMKeyPIN" -value 2
}
#Check UseTPMPIN value is correct, if not set it to be correct value.
Get-ItemProperty -Path hklm:\SOFTWARE\Policies\Microsoft\FVE -name "UseTPMPIN"
if($val.UseTPMPIN -ne 2)
{
Set-ItemProperty -Path hklm:\SOFTWARE\Policies\Microsoft\FVE -Name "UseTPMPIN" -value 2
}
#Prompt the user to enter a password, which will be stored as a string and used to set Bitlocker password
$pass = Read-Host 'Please set new password' -AsSecureString
#Enable BitLocker on Drive C: with password set by user and encrypt used space only.
Enable-BitLocker -MountPoint "C:" -Password $pass -EncryptionMethod Aes256 -UsedSpaceOnly -PasswordProtector
#Generate Recovery Key and store in C:\Recovery
Get-BitLockerVolume | Enable-BitLocker -EncryptionMethod Aes256 -RecoveryKeyPath "C:\Recovery" -RecoveryKeyProtector
#Save Recovery Key to C:
(Get-BitLockerVolume -MountPoint C:).KeyProtector > $env:UserProfile\Desktop\BitLocker_Recovery_Key.txt
当我添加这部分时:
Get-BitLockerVolume | Enable-BitLocker -EncryptionMethod Aes256 -RecoveryKeyPath "C:\Recovery" -RecoveryKeyProtector
在桌面上生成的 recoverykey.txt 文件有“Recovery Key”的部分,但它是空白的,而且这一行还会导致错误,指出我需要重新启动才能启动 Bitlocker 才能运行。
谁能给我一些关于为什么 .txt 中缺少恢复密钥以及我是否在任何地方出错的指示?
谢谢。