首页 > 解决方案 > Bitlocker 远程加密并使用 PS 脚本输出到 Active Directory

问题描述

我正在 PowerShell 中编写一个不寻常的脚本。

我需要一个脚本,该脚本根据创建为.txt文件的 pc 列表连接到 PC,并执行以下操作:

  1. 激活本地组策略中的 TPM 芯片,即使工作站没有它
  2. 使用 Bitlocker 启动磁盘加密
  3. 它将恢复密钥保存在 AD 中
  4. 加密目标计算机
  5. 它重新启动PC

我有一个脚本如下: 它的工作原理如下:它连接到给定的 PC 并将生成的密钥保存到 AD。计算机做了一些事情,但它永远不会重新启动并加密 PC。我不知道在哪里看。

我欢迎任何改进:) 我想知道您是否可以告诉我如何真正加密并重新启动 PC,然后如何创建自己的加密代码,格式为:<公司名称>和站名的最后 4 个字符. 例如:PC 名称是:FRTW144> 键必须是CompanyName W144。

我会为我可以测试的任何改进感到高兴。

$List = Get-Content "C:\list.txt" 

Import-Module ActiveDirectory


Enable-PSRemoting -Force


Restart-Service WinRM


Invoke-command -ComputerName $List -ScriptBlock{Get-Tpm | Select-Object -ExpandProperty Tpmready}
Invoke-command -ComputerName $List -ScriptBlock{Get-Bitlockervolume -MountPoint 'C:'}

New-Object psobject -Property @{TPM=$tpmready;Bitlocker=$BLinfo.ProtectionStatus}


Invoke-command -ComputerName $List -ScriptBlock{Add-BitLockerKeyProtector -MountPoint 'C:' -RecoveryPasswordProtector}
Start-Transcript -Path "C:\bitlockertranscript.txt" -Force  
foreach ($Computer in $List) {   

        if (test-Connection -ComputerName $Computer -Count 1 -Quiet ) {    

            Get-ADComputer -Identity $Computer -Property * | Select Name,OperatingSystem 
            Get-WmiObject -class Win32_Tpm -namespace root\CIMV2\Security\MicrosoftTpm  -computername $Computer | fl IsActivated_InitialValue, IsEnabled_InitialValue, IsOwned_InitialValue   
            $BitLocker = Get-WmiObject -ComputerName $Computer -Namespace Root\cimv2\Security\MicrosoftVolumeEncryption -Class Win32_EncryptableVolume 
            $id = $BitLocker.GetKeyProtectors(3).volumekeyprotectorid | Select -First 1 
            manage-bde -on c: -pw -rp
            manage-bde.exe -cn $Computer -protectors -adbackup c: -id $id 
            manage-bde.exe -on C: -cn $Computer 
            „Encryption complete
                    } else   

                    {"Can’t connect to  $Computer "}       

} 

Restart-Computer $Computer
Stop-Transcript

标签: powershellencryptionactive-directorybitlocker

解决方案


推荐阅读