PowerShell for Windows Admins

May 26 2017   8:53AM GMT

Diskpart and PowerShell – part 6: Multiple partitions on a disk

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Disk storage

So far we’ve looked at creating a single partition on a disk. This time we’ll look at how you can create multiple partitions on a disk. The are good reasons not to do this but its something I’ve seen done on a frequent basis.

Lets create a 20GB disk as an example and mount it

New-VHD -Path C:\test\Test1.vhdx -Dynamic -SizeBytes 20GB
Get-VHD -Path C:\test\Test1.vhdx | Mount-VHD

Initialise the disk

Initialize-Disk -Number 1

Now we can create some partitions

New-Partition -DiskNumber 1 -DriveLetter F -Size 5GB
New-Partition -DiskNumber 1 -DriveLetter G -Size 5GB
New-Partition -DiskNumber 1 -DriveLetter H -Size 5GB
New-Partition -DiskNumber 1 -DriveLetter I -Size 4.87GB

The reason that the last partition is only 4.87 G is that 128MB of disk space is reserved

PS> Get-Partition -DiskNumber 1 | Format-Table -AutoSize

   DiskPath: \\?\scsi#disk&ven_msft&prod_virtual_disk#2&1f4adffe&0&000003#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}

PartitionNumber DriveLetter Offset         Size Type
--------------- ----------- ------         ---- ----
1                           17408        128 MB Reserved
2               F           135266304      5 GB Basic
3               G           5503975424     5 GB Basic
4               H           10872684544    5 GB Basic
5               I           16241393664 4.87 GB Basic

You can format the 4 new volumes in one pass

Get-Partition -DiskNumber 1 | 
where Type -ne 'Reserved' | 
Format-Volume -FileSystem NTFS -Confirm:$false –Force

PS> Get-Partition -DiskNumber 1 | Get-Volume | select DriveLetter, FileSystem, Size

DriveLetter FileSystem       Size
----------- ----------       ----
          H NTFS       5368705024
          G NTFS       5368705024
          I NTFS       5229244416
          F NTFS       5368705024

The Storage module can be used to simply and easily create multiple volumes on a disk

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: