Diskpart and PowerShell–part 4: Expand a volume

Let’s create a new disk and mount it

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

This time we’ll create a volume that only uses part of the disk

New-Partition -DiskNumber 1 -DriveLetter F -Size 5GB

And now format the partition

Get-Partition -DriveLetter F |
Format-Volume -FileSystem NTFS -Confirm:$false –Force

The disk is organised like this

Get-Disk -Number 1 | 
Select @{N='Size'; E={[math]::Round(($_.Size / 1GB), 2)}}, 
 @{N='AllocatedSize'; E={[math]::Round(($_.AllocatedSize / 1GB), 2)}}, 
@{N='LargestFreeExtent'; E={[math]::Round(($_.LargestFreeExtent / 1GB), 2)}} |
Format-List

Size              : 20
AllocatedSize     : 5.13
LargestFreeExtent : 14.87

Lets expand the partition

Get-Partition -DriveLetter F | 
Resize-Partition -Size 8GB

And re-examine the disk organisation

Get-Disk -Number 1 | 
Select @{N='Size'; E={[math]::Round(($_.Size / 1GB), 2)}}, 
 @{N='AllocatedSize'; E={[math]::Round(($_.AllocatedSize / 1GB), 2)}}, 
@{N='LargestFreeExtent'; E={[math]::Round(($_.LargestFreeExtent / 1GB), 2)}} |
Format-List

Size              : 20
AllocatedSize     : 8.13
LargestFreeExtent : 11.87

The extra space is added to the volume and formatted to match the existing filesystem on the volume

Advertisements
This entry was posted in Powershell, Storage. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s