DiskPart Command-Line Options command-line tool

You can create scripts to automate disk-related tasks, such as creating volumes or converting disks to dynamic disks.

Scripting these tasks is useful if you deploy Windows by using unattended Setup or the Sysprep tool, which do not support creating volumes other than the boot volume.

For more information about DiskPart scripts, see "Disk Management" in the Microsoft Windows XP Professional Resource Kit.

For starting a DiskPart script, at the command prompt, type:

  1. diskpart/s scriptname.txt where scriptname is the name of the text file that contains your script.

For redirecting DiskPart's scripting output to a file, type:

  1. diskpart /s scriptname.txt > logfile.txt where logfile is the name of the text file where DiskPart writes its output.

DiskPart starts and version and computer name display at the command prompt. By default, if DiskPart encounters an error while attempting to perform a scripted task, DiskPart stops processing the script and displays an error code (unless you specified the noerr parameter).

Keep in mind, DiskPart always returns errors when it encounters syntax errors, regardless of whether you used the noerr parameter.

The noerr parameter enables you to perform useful tasks such as using a single script to delete all partitions on all disks regardless of the total number of disks.

A lists of the DiskPart error codes:

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