Being able to automate disk partitioning, volume creation, and filesystem formatting can be very useful. It is especially handy for imaging processes, e.g. from a WinPE boot disk.
The windows diskpart command can be automated using a simple text file. Unfamiliar with Diskpart? Open Windows Command Processor (cmd.exe) and type:
If you want help with a specific command, type:
Where <command> is the command that you want help with.
To automate diskpart, you simply need to create a text file with your diskpart commands, then call diskpart from your command prompt or script and pass it the name of the text file.
For example, let’s say that you have booted a computer to WinPE, and wish to wipe the local “C:” drive and create a fresh one. To do so, open notepad.exe, then type the following:
select disk 0
create partition primary
format fs=ntfs label=Windows quick
Now save that as WipeC.txt and close Notepad.
Then run it like so:
diskpart.exe /s WipeC.txt
Please note that this example will completely remove the contents of the local Disk 0!
More specifically, it will: wipe all partitions off of Disk 0, create a single primary partition which will occupy the whole disk, assign that partition the drive letter C:, set it as active so that you can boot from it, and then create a volume called “Windows” formatted quickly as NTFS.