Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Mar 2009
    Somewhere Over the Rainbow
    Thanked 1 Time in 1 Post

    Question Batch file to put Hard Drives in Online / Offline Mode Disk Management

    Hello Everyone! Long time since I made a post to this wonderful forum. Hope everyone is doing well. And now back to business.....

    I am looking to make a batch file that will do set some hard drives offline in disk management.

    I know how to set hard drives to power down when not in use from windows, but it isn't perfect. I would prefer a more manual on demand way to put a drive offline and back online.

    I mentioned doing this in batch because I am somewhat familiar with it and it seems like a job for a batch file for simplicity.

    Basically instead of going into disk management every time and right clicking on a drive and clicking offline, I want an easy one click or double click method.

    My work computer has a bootable SSD drive and about 5 Hard Drives, but the number of hard drives really doesn't make a difference. The problem is sometimes when opening a program that is in now way using an of my hard will still spin them all up which forces me to wait until I can continue using my SSD. Besides, I rarely need access to those drives, maybe twice a week.

    Thanks in advance,

  2. The Following User Says Thank You to handyandy For This Useful Post:

    Fascist Nation (2016-04-08)

  3. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Manning, South Carolina
    Thanked 1,609 Times in 1,453 Posts

    You can use this Powershell method. Just create 2 PS Scripts and then 2 shortcuts to call them assigning each a Hot key and you'll be in business.

    P.S. I tested this on my 64 bit Win 7 backup system and it worked just fine.

    May the Forces of good computing be with you!


    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  4. #3
    New Lounger
    Join Date
    Apr 2016
    Thanked 1 Time in 1 Post

    Take Volume Offline/Online

    Here is a script that will take a disk offline and back online using the volume name. You can essentially use this script run DiskPart commands.

    To use this script, set the DeviceVolumeName and DeviceFileSystem.

    Modify to suit your needs.

    @echo off
        :: Set the following to the desired values
        set DeviceVolumeName=Enterprise
        set DeviceFileSystem=NTFS
        set DeviceType=Partition
        ::set TempPath=%systemdrive%
        ::set TempPath=%TEMP%
        set TempPath=.
        title "%DeviceVolumeName% Drive Offliner/Onliner"
        echo %DeviceVolumeName% Drive Offliner/Onliner
        :: Clear the DeviceVolumeNumber in case it exists
        set DeviceVolumeNumber=
        :: Create a script file to be used by diskpart and then dump all volumes to a temp file
        echo list volume > %TempPath%\ListDrives.tmp
        diskpart /s %TempPath%\ListDrives.tmp > %TempPath%\CurrentDrives.tmp
        :: Parse the output from 'Diskpart > list volume' for available volumes
        echo   Checking for %DeviceVolumeName% volume that needs to be taken offline and back online.
        :: %%a - Volume ###
        :: %%b - Driver letter
        :: %%c - Label
        :: %%d - File system (e.g. NTFS)
        :: %%e - Type (e.g. Removable, CD-ROM, DVD-ROM, Partition)
        for /F "skip=7 tokens=2-6" %%a in (%TempPath%\CurrentDrives.tmp) do (
            echo     %%b %%c %%d %%e
            @if /I "%%c %%d %%e" == "%DeviceVolumeName% %DeviceFileSystem% %DeviceType%" (
                :: DeviceVolumeNumber will be set to the volume number you want to operate on.
                echo   %%c was found to have a drive letter %%b and will be taken offline and back online.
                set DeviceVolumeNumber=%%a
        :: Decide what to do next.  Was the device found?
        ::   Yes - perform action.
        ::   No  - exit.
        if DEFINED DeviceVolumeNumber (goto PrepareCommands) else (goto CleanUp)
        :: Remove DiskPartCommands.tmp if it exists because we'll append to it.
        if exist %TempPath%\DiskPartCommands.tmp del /q /f %TempPath%\DiskPartCommands.tmp 1>nul 2>nul
        :: Append Diskpart commands to DiskPartCommands.tmp
        echo select volume %DeviceVolumeNumber% >> %TempPath%\DiskPartCommands.tmp
        echo offline disk >> %TempPath%\DiskPartCommands.tmp
        echo online disk >> %TempPath%\DiskPartCommands.tmp
        set DeviceVolumeNumber=
        goto ExecuteCommands
        :: Run diskpart using the new script file, wait 15 seconds before running per a note on
        echo   Taking device offline and back online...
        ping -n 15 localhost 1>nul 2>nul
        diskpart /s %TempPath%\DiskPartCommands.tmp 1>nul 2>nul
        goto CleanUp
        :: Delete the script files
        if exist %TempPath%\ListDrives.tmp del /q /f %TempPath%\ListDrives.tmp 1>nul 2>nul
        if exist %TempPath%\CurrentDrives.tmp del /q /f %TempPath%\CurrentDrives.tmp 1>nul 2>nul
        if exist %TempPath%\DiskPartCommands.tmp del /q /f %TempPath%\DiskPartCommands.tmp 1>nul 2>nul
        echo Done...
        set DeviceVolumeName=
        set DeviceFileSystem=
        set DeviceType=
        set TempPath=
        set DeviceVolumeNumber=
        exit /b 0

  5. The Following User Says Thank You to spitfire For This Useful Post:

    BHarder (2016-04-05)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts