Reputation: 13
I am trying to create a bat file to run cmd code to save bitlockers numeric id to ad the code I got that far is
@echo off
title bitlocker to AD.
echo Bitlocker to ActiveDirectory
pause
powershell -Command manage-bde -protectors -get c:
powershell -Command manage-bde -protectors c: -id {<numericalpassword>}
echo 1)Exit
set input=
set /p input= Choice
if %input%==2 goto Exit if NOT goto Start 2```
`
But what I got when I run it is:
[![what really happened][1]][1]
[1]: https://i.sstatic.net/uM3b9.png
basically it cannot recognize the "<numericalpassword>"
How to I get the numerical password id as a string that I can push to the second line?
Upvotes: 0
Views: 1567
Reputation: 1
powershell -Command manage-bde -protectors -get c:
Just so. manage-bde is an .exe file (CMD) and not a PowerShell command. But Powershell is probably useful for cutting the key.
Upvotes: 0
Reputation: 1
I'm getting this when I try to run:
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& 'path-to-your-powershell-script'"
Output:
C:\Users>$key = ((manage-bde -protectors -get c:) | Select-String -SimpleMatch "ID: ")[1] -replace "ID:","" -replace " ","" '$key' is not recognized as an internal or external command, operable program or batch file.
Upvotes: 0
Reputation: 3137
I have tested in my environment
how to i get the numerical password id as a string that i can push to the second line ?
You can use the below command to get the numerical password id as a string variablee :
$key = ((manage-bde -protectors -get c:) | Select-String -SimpleMatch "ID: ")[1] -replace "ID:","" -replace " ",""
Now you can use this variable in the second line as follows :
manage-bde -protectors -adbackup c: -id $key
Also, you can write the powershell script for the two powershell commands and run the script in the bat file.
Use the below powershell script :
$key = ((manage-bde -protectors -get c:) | Select-String -SimpleMatch "ID: ")[1] -replace "ID:","" -replace " ",""
manage-bde -protectors -adbackup c: -id $key
Save this script in your local and use this line in your bat file :
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& 'path-to-your-powershell-script'"
Instead of
powershell -Command manage-bde -protectors -get c:
powershell -Command manage-bde -protectors c: -id {<numericalpassword>}
Upvotes: 0