DISKPART Information

DISKPART is a Windows program that replaces FDISK. FDISK only works with MBR partitions. DISKPART works on MBR and GPT partitions. Type HELP DISKPART in a command window to see all the options for DISKPART.

Open a command window as an administrator in order to call DISKPART.

DISKPART can be used interactively or can be called from scripts. The following can be issued in interactive mode, after typing DISKPART in a command window. To run DISKPART from a script file, place DISKPART commands in a text file (not .bat) and execute the script file with

DISKPART /S MYFILE.TXT

Useful commands

LIST DISK
List all the available disks on the system.
SELECT DISK N
Choose a disk by number.
CLEAN
Erase a disk entirely. Partition table and all partitions are erased. This command can only be executed after issuing a SELECT DISK command.
CONVERT TYPE
Create the partition table for the disk. This command can only be executed after issuing a SELECT DISK command. Type can be BASIC or DYNAMIC for converting between the type of disk; type can be MBR or GPT for converting between type of partition table. GPT has a minimum size restriction.
CREATE PARTITION TYPE SIZE=N
Creates a partition of the given type of size N, in Mebibytes. This command can only be executed after issuing a SELECT DISK command. The type of the partition can be primary, extended or logical.
LIST PARTITION
List all the available partitions on the current disk. This command can only be executed after issuing a SELECT DISK command.
SELECT PARTITION N
Select a partition by number. This command can only be executed after issuing a SELECT DISK command.
FORMAT FS=TYPE LABEL=TEXT
Format the current partition. This command can only be executed after issuing a SELECT PARTITION command. Type is either FAT or NTFS. LABEL is a string that appears in Windows Explorer that helps identify the partition. If the string has spaces, enclose the string in quotes.
LIST VOLUME
List information on all the volumes on all disks.

Before working on a disk or partition, it must be selected.

Help for any command can be listed with HELP COMMAND. If a command has options, then help on the option can be obtained with HELP COMMAND OPTION.

Scripting with DISKPART

Create a text file with DISKPART commands.

list disk
select disk 1
list partition

Run DISKPART from an administrator's command window:

DISKPART /S MYSCRIPT.TXT

The output of the command will look something like

Microsoft DiskPart version 6.2.9200

Copyright (C) 1999-2012 Microsoft Corporation.
On computer: WIN8-HOME

  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online           40 GB  1024 KB         
  Disk 1    Online           20 MB  8128 KB         
  Disk 2    Online           20 MB    20 MB         

Disk 1 is now the selected disk.

  Partition ###  Type              Size     Offset
  -------------  ----------------  -------  -------
  Partition 1    Primary           4096 KB    64 KB
  Partition 5    Primary           7168 KB    10 MB

Redirect the output to a file with:

DISKPART /S MYSCRIPT.TXT > DISKPART.OUT.TXT