Search notes:

diskpart.exe

diskpart.exe can be used to display and configure file system partitions. It is a command line program and thus can be used in cmd.exe.
When working with diskpart.exe, the available objects must first be listed (for example with list disk) and then an object must be selected (for example select disk …).

list disk

list disk shows the disks.
DISKPART> list disk

  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online          476 GB    14 MB        *
  Disk 1    Online         1947 MB    12 MB
list disk can be used to show if a harddisk uses a MBR (column Gpt contains no star), or a GPT partition (column Gpt contains a star).
Note: the Free column (which in the example above shows 14 MB) does not say how much space is free in the file system but rather how much space is not allocated for a file system.

select disk

select disk n shifts focus on the nth disk.
DISKPART> select disk 0
Selecting a disk is needed, for example, to list a disk's partition.

list partition

list partition shows the partitions of the selected disk.

list volume

list volume shows the volumes.
DISKPART> list volume

  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 0     C   OS           NTFS   Partition    475 GB  Healthy    Boot
  Volume 1         WINRETOOLS   NTFS   Partition    990 MB  Healthy
  Volume 2         ESP          FAT32  Partition    650 MB  Healthy    System
  Volume 3     D                FAT    Removable   1935 MB  Healthy
list volume can be abbreviated with lis vol.

select volume

select volume 3
With a selected volume, another list volume shows a star to the left side of the selected volume.
select volume can be abbreviated with sel vol.

filesystems

filesystems shows the supported file systems on a volume.
DISKPART> filesystems

Current File System

  Type                 : FAT
  Allocation Unit Size : 32K
  Flags : 00000000

File Systems Supported for Formatting

  Type                 : NTFS
  Allocation Unit Sizes: 512, 1024, 2048, 4096 (Default), 8192, 16K, 32K, 64K, 128K, 256K, 512K, 1024K, 2048K

  Type                 : FAT (Default)
  Allocation Unit Sizes: 32K (Default), 64K

  Type                 : FAT32
  Allocation Unit Sizes: 512, 1024, 2048, 4096 (Default), 8192, 16K

  Type                 : exFAT
  Allocation Unit Sizes: 512, 1024, 2048, 4096, 8192, 16K, 32K (Default), 64K, 128K, 256K, 512K, 1024K, 2048K, 4096K, 8192K, 16384K, 32768K

format

format formats the selected volume
DISKPART> format fs=fat

Take a disk offline

A disk can be taken offline, for example because MsMpEng.exe prevents a USB drive from being ejected:
C:\> dispkart

DISKPART> list disk

  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online          223 GB      0 B
  Disk 1    Online          931 GB      0 B

DISKPART> select disk 1

Disk 1 is now the selected disk.

DISKPART> offline

Removing a drive letter

Apparently, a USB drive (that for example is mounted on D:) can be removed (ejected) with remove letter=d.
For a reason that I don't understand, a volume needs to be selected first:
DISKPART> sel vol 4
DISKPART> remove letter=d
Note: remove cannot be abbreviated with rem because rem indicates a comment (remark).

Scripts

diskpart can be invoked with the /s command to run scripts:
diskpart /s theScript.txt

See also

The Linux shell command parted.
cmd.exe: Built-in commands

Index