Initialize and format a new disk with PowerShell

Posted: (EET/GMT+2)

 

If you need to prepare a new disk on Windows Server, you can do the basic disk setup directly from PowerShell.

The main cmdlets are Get-Disk, Initialize-Disk, New-Partition, and Format-Volume.

First, list the disks visible to Windows:

Get-Disk

A new disk usually appears with PartitionStyle set to zero (0) or RAW.

Number Friendly Name        Serial Number HealthStatus OperationalStatus Total Size PartitionStyle
------ -------------        ------------- ------------ ----------------- ---------- --------------
0      Msft Virtual Disk                  Healthy      Online                80 GB GPT
1      Msft Virtual Disk                  Healthy      Online               100 GB RAW

In this example, disk 1 is the new empty disk.

Initialize it using a GPT (GUID Partition Table) partition:

Initialize-Disk -Number 1 -PartitionStyle GPT

Then create a partition that uses the full disk and assign a drive letter, such as F:\:

New-Partition -DiskNumber 1 -UseMaximumSize -DriveLetter F

Finally, format the new volume as NTFS:

Format-Volume -DriveLetter F -FileSystem NTFS -NewFileSystemLabel "Data" -Confirm:$false

You can verify the result with:

Get-Volume -DriveLetter F

Tip: always double-check the disk number before running Initialize-Disk. Initializing or formatting the wrong disk is a fast way to destroy data. So take care!

If you want to find only uninitialized disks, you can filter by PartitionStyle:

Get-Disk | Where-Object PartitionStyle -eq 'RAW'

For a simple one-disk setup, the full sequence is:

Get-Disk | Where-Object PartitionStyle -eq 'RAW'

Initialize-Disk -Number 1 -PartitionStyle GPT

New-Partition -DiskNumber 1 -UseMaximumSize -DriveLetter F

Format-Volume -DriveLetter F -FileSystem NTFS -NewFileSystemLabel "Data" -Confirm:$false

This sequence is useful for new virtual machines, lab servers, or freshly attached data disks.