1

I've been trying to create an easier way for my team to get the bitlocker status of devices on our network. After checking through a bunch of seperate answers on here and other sites I've managed to cobble together an almost working batch script, however it doesn't seem to be pulling the entry correctly. Code is below:

@echo off
color a
title BitLocker Checking
:start
cls
setlocal EnableDelayedExpansion

set i=0
for /F %%a in ('net view') do (
   set line=%%a
   if "!line:~0,2!" equ "\\" (
      set /A i+=1
      echo [!i!]        !line:~2!
      set comp[!i!]=!line:~2!
   )
)

echo.
echo.
echo Choose a computer.
choice /c 12345678 >nul
set name=!comp[%errorlevel%]!

cls
for /f "tokens=1,2 delims=[]" %%A in ('manage-bde -status -computername %name% ^| find "Conversion Status"') do set derp=%%B
if "%name%"=="" goto start
echo The status of %name% is %derp%
echo.
echo.
echo %derp% | clip
echo. %derp% copyied to clipboard.
echo.
echo Press any key.
pause 
goto start

When I take the manage-bde -status -computername %name% | find "Conversion Status" line in isolation and provide it with a computername, it seems to pull the conversion status line correctly (e.g. "Conversion Status : Fully Decrypted" if bitlocker is off on the machine). However if left in context of the batch file, it outputs "The status of computernamegoeshere is" and then a blank, as if it's not getting the data from the Find command into the variable %B.

Anyone have any suggestions? It's been a while since I've written batch commands so a bit rusty.

GM_Soul
  • 13
  • 5
  • I don't see any `[]` characters in the resulting output, so your `delims=[]` seems to be wrong. What version of Windows are you running this on? – jwdonahue Sep 05 '18 at 04:53
  • Shouldn't `if "%name%"=="" goto start` happen before the `for` loop? – jwdonahue Sep 05 '18 at 04:55
  • @jwdonahue Windows 10 currently, but aiming to push it out on a bit of a range due to some of our system setups. – GM_Soul Sep 06 '18 at 02:52

1 Answers1

0

I think the extra white space in the output is messing with you. On Win10 command line, this works for me:

for /f "tokens=1,*" %A in ('manage-bde -status -computername %COMPUTERNAME% ^| findstr Conversion') do echo %A %B

Resulting in output (minus prompt noise):

Conversion Status:    Fully Decrypted
Conversion Status:    Fully Decrypted
Conversion Status:    Fully Decrypted

So you need to remove the delims=[], change tokens=1,2 to tokens=1,* and whether you use find or findstr is up you. My preference is findstr.

jwdonahue
  • 6,199
  • 2
  • 21
  • 43