Re-Save the BitLocker key of a Local or Remote PC to AD

Remote PC

#Remember to save this file as a .ps1 PowerShell script for easy access.

#Create cmpName variable and prompt for computer name
$CmpName = Read-Host -Prompt 'Enter Computer Name: '

#create a variable to store the contents of the protectors / keys available
$currentProtectors = manage-bde -protectors C: -cn $CmpName -get

#Use select-string to identify the Numerical Password
$NumericPass =  $currentProtectors | Select-String -Pattern 'Numerical Password:' -Context 0,1

#split the string by using the '{' char to only grab the ID
$NumericID = ($NumericPass -split "({)",2)[2]

#cut off the last bracket in NumbericID by selecting the substring -1
$NumPassID = $NumericID.Substring(0,$NumericID.Length-1)

#last command to backup the key to AD
manage-bde -protectors -adbackup C: -cn $cmpName -id "{$NumPassID}"

pause