I am using this rudimentary code to format hard drives in an enclosure, I can modify this since I have 2 bay and 4 bay enclosures. Here's the question: Whatever computer I use to run this code has different amounts of hard drives already installed. In this example, I need MBR with quick format and the drives are disk 3 and 4. In another computer, they may be 1 and 2 or 4 and 5 etc. I saved this as quickformat.txt. I am running it in Windows Terminal using "diskpart /s c:\temp\quickformat.txt" It works fine, only thing is I want to automate it to ask me for the disk numbers upon running the script instead of having to modify the script every time, can this be done? Other options to add would be MBR or GPT and FULL or QUICK format. TIA Code: select disk 3 clean convert mbr create partition primary format quick fs=ntfs label="Disk 1" assign select disk 4 clean convert mbr create partition primary format quick fs=ntfs label="Disk 2" assign
I know what you are trying to do. The only thing I can think of is to write a command file which lets you input the values, then have it write all that to a text file for diskpart to call.
Why do you need a script when without it you can format with two mouse clicks but using a script with many more clicks.
Because sometimes I need to do a full format on 4 drives in an enclosure and I don't have the time to sit there and watch it. I can use a script to let it run overnight. I'm also a believer that a computer should work for me instead of the other way around. I'd rather run a script and walk away. Isn't stuff like this all part of the fun of what we used to call "hacking" in the 80's?
my way of doing things. take arguments like E F G I hope its useful for you. credit its yours. Edit [1]: you should use :: setlocal enabledelayedexpansion Edit [2]: its clean all partitions found on this drive Edit [3]: its E not E: or E:\ just pure letter Code: :CleanDrive set diskIndex= set volumeIndex= set targetDrive=%* pushd %SystemDrive% >"%temp%\tmp" echo list volume for /f "tokens=1,2,3 delims= " %%m in ( 'diskpart /s "%temp%\tmp"') do ( if /i 'Volume' EQU '%%m' ( if /i '%targetDrive%' EQU '%%o' ( REM echo Volume [%%n] Letter [%%o] set volumeIndex=%%n ) ) ) if defined volumeIndex ( >"%temp%\tmp" echo select volume !volumeIndex! >>"%temp%\tmp" echo list disk ) for /f "tokens=1,2,3 delims= " %%m in ( 'diskpart /s "%temp%\tmp"') do ( if /i '*' EQU '%%m' ( REM echo Select Disk [%%o] set diskIndex=%%o ) ) if defined diskIndex ( >"%temp%\tmp" echo select disk !diskIndex! >>"%temp%\tmp" echo clean >>"%temp%\tmp" echo clean >>"%temp%\tmp" echo Convert gpt >>"%temp%\tmp" echo create partition primary >>"%temp%\tmp" echo Select partition 1 >>"%temp%\tmp" echo Format quick fs=ntfs >>"%temp%\tmp" echo ASSIGN LETTER=%targetDrive% ) 1>nul diskpart /s "%temp%\tmp" popd goto :eof
Dark Monkey, thank you so much for your help, I will try this tonight once I get home from work. I really appreciate it!
This is what I used in WinPE ages ago: Code: @echo off :: FM X - Clean, Format, Label as Data and Assign if "%1"=="/?" goto Help if "%1"=="" goto Help Set FMDisk=%1 echo sel dis %FMDisk% >x:\tmp.txt echo cle >>x:\tmp.txt echo cre par pri >>x:\tmp.txt echo for quick fs=ntfs label="Data" >>x:\tmp.txt echo assign >>x:\tmp.txt diskpart /s x:\tmp.txt del x:\tmp.txt /q /f goto eof :help echo FM X - Clean, Format, Label as Data and Assign. echo. echo - Where X is the Drive to format... echo. goto eof :eof You can change x: to %temp% and add convert to mbr or gpt...