For Each Drive in batch file

StewartBW 1,145 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!

C#
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.
10,932 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,727 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Marcin Policht 24,120 Reputation points MVP
    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 Answers by the question author, which helps users to know the answer solved the author's problem.