6.1 Partition Manager

DiskPart is a text-mode command interpreter in Windows 7, Windows Vista, Windows® XP, and the Windows Server 2003® family. This tool enables you to manage objects (disks, partitions, or volumes) by using scripts or direct input at a command prompt.

DiskPart Scripting

This section describes:

  • DiskPart Commands
  • DiskPart Scripting

DiskPart Commands

Before you can use DiskPart commands on a disk, partition, or volume, you must first list and then select an object to give it focus.

When an object has focus, any DiskPart command that you input will affect that particular object.

You can list the available objects and determine an object's number or drive letter by using the list disk, list volume, and list partition commands.

The list disk and list volume commands display all disks and volumes in the computer. However, the list partition command displays only partitions on the disk that have focus.

When you use the list commands, an asterisk (*) appears next to the object with focus. You select an object by its number or drive letter, such as disk 0, partition 1, volume 3, or volume C.

When you select an object, the focus remains on that object until you select a different object. For example, if the focus is set on disk 0, and you select volume 8 as on disk 2, the focus shifts from disk 0 to disk 2, volume 8. Some commands automatically change the focus. For example, when you create a new partition, the focus automatically changes to the new partition.

You can give focus only to a partition on the selected disk. When a partition has focus, the related volume (if any) will also have focus. When a volume has focus, the related disk and partition also have focus if the volume maps to a single specific partition. If this is not the case, then focus on the disk and partition is lost.

When using the DiskPart command as a part of a script, it is recommended that you complete all of the DiskPart operations together as part of a single DiskPart script.

You can run consecutive DiskPart scripts, but you must allow at least a 15 second time gap between each script. Before running the DiskPart command again in successive scripts the previous execution needs to be completed. Otherwise, the successive scripts might fail. You can add a pause between consecutive DiskPart scripts by adding the timeout /t 15 command to your batch file along with your DiskPart scripts.


> DiskPart.exe ?

To see all DiskPart commands and syntax.

For more information about DiskPart, see Disk Management at the Microsoft TechNet Web site

DiskPart Scripting

By using the 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.

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

diskpart /s scriptname .txt

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

To redirect DiskPart's scripting output to a file, type:

diskpart /s scriptname .txt > logfile .txt

where logfile is the name of the text file where DiskPart writes its output.

When DiskPart starts, the DiskPart 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). However, 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. The table below lists the DiskPart error codes.

The table below lists the DiskPart error codes.