For Each Drive in batch file

StewartBW 1,905 Reputation points
2024-04-12T23:28:31.4133333+00:00

Hello

These commands inside a .bat batch file will disable bit locker for C:, D:...

manage-bde -off C:

manage-bde -off D:

...

Is it possible that using batch file (not powershell) I loop through existing drives and run the above command for each drive in system drives? If so, should be simple, but I've no knowledge of batch file scripting :(

Please help

Sorry didn't know which tags to choose!

Developer technologies | VB
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
{count} votes

1 answer

Sort by: Most helpful
  1. Marcin Policht 72,695 Reputation points MVP Volunteer Moderator
    2024-04-12T23:46:40.4566667+00:00

    Try the following

    @echo off
    setlocal enabledelayedexpansion
    REM Get the list of drive letters
    for /f "tokens=2 delims==:" %%d in ('wmic logicaldisk get caption^,drivetype ^| find "3"') do (
        set "drive=%%d"
        echo Disabling BitLocker for drive !drive!...
        manage-bde -off !drive!:
    )
    echo All BitLocker drives have been disabled.
    pause
    
    

    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.