Powershell – Set up disk volume from scratch using Initialize-Disk, Get-Disk, New-Partition and Format Volume

You may wish to script the process of setting up a disk volume.

The example in this post covers initializing the disk using GPT, creating the partition using the maximum size on the disk, and then formatting the partition using NTFS.

Notes

  1. GPT – GUID partition table (GPT) is required for disks larger than 2 terabytes.
  2. NTFS – New Technology File System (NTFS) is the file system used on modern Windows Operating Systems.
  3. I believe these commandlets are available to Windows 8, Windows 2012 and above.

Code description

  1. You specify the disk number that requires initialization in $DiskNumber
  2. You specify the desired volume name in $VolumeName
  3. The disk is initialized and set to use the GPT partition style
  4. The disk has a partition created on it using all available storage, and gives it the volume name
  5. The volume is formatted using the NTFS file system and given a label of “Data”

Code

$DiskNumber = 1
$VolumeName = "E:\"

Initialize-Disk -Number $DiskNumber -PartitionStyle GPT

Get-Disk -Number $DiskNumber | New-Partition -UseMaximumSize -DriveLetter $VolumeName

Format-Volume -DriveLetter $VolumeName -FileSystem NTFS -NewFileSystemLabel "Data"

 

One thought on “Powershell – Set up disk volume from scratch using Initialize-Disk, Get-Disk, New-Partition and Format Volume

Leave a comment