Batch – Verify Returned Values are Numbers

email me

So, this came about because I was looking at an old script that uses manage-bde.exe to return the Bitlocker. No big deal,really, but…apparently someone forgot to actually verify the returned value was at least numbers.

This was the command

for /f “skip=5 tokens=1 delims=Password ” %%h in (‘”c:\windows\system32\manage-bde.exe -protectors -get c:”‘) do set BitPass=%%h

Which returns something like this

123456-123456-123456-123456-123456-123456-123456-123456

What I added was this

SET “var=”&for /f “delims=0123456789-” %%i in (“%BitPass%”) do set var=%%i
if defined var (exit)

What this does is compare BitPass to the specified delimiters, if it matches…it continues; if not, it exists.