Skip to content. | Skip to navigation

Personal tools


You are here: Home / Wiki / Diskpart



DiskPart.exe is a text-mode command interpreter that enables you to manage objects (disks, partitions, or volumes) by using scripts or direct input from a command prompt. Before you can use DiskPart.exe commands on a disk, partition, or volume, you must first list and then select the object to give it focus. When an object has focus, any DiskPart.exe commands that you type act on that object.

DiskPart scripting

Using DiskPart, you can create scripts to automate disk-related tasks, such as creating volumes or converting disks to dynamic. Scripting these tasks is useful if you are deploying Windows by using Unattended Setup or Sysprep, which do not support creating volumes other than the boot volume

To start a DiskPart script, at the command prompt, type:

DiskPart /S scriptname.txt

Where scriptname.txt is the name of the text file that contains your script.

A sample script to create single NTFS primary partition with label as "windows",with drive letter as "C"

select disk 0
create partition primary
select partition 1
format fs=ntfs label="windows" quick
assign letter=c

The following table lists the DiskPart error codes:

0 No errors occurred. The entire script ran without failure.
1A fatal exception occurred. There may be a serious problem.
2The parameters specified for a DiskPart command were incorrect.
3DiskPart was unable to open the specified script or output file.
4One of the services DiskPart uses returned a failure.
5A command syntax error occurred. The script failed because an object was improperly selected or was invalid for use with that command.

For more detail please refer to DiskPart Reference