PowerShell, Windows

How To: Resize Disk Partition with PowerShell

If you need to expand a disk partition on a Windows system (which has PowerShell) then you can quickly and efficiently do so with the following commands further down.

Step 1 – Use Get-Volume to identify the disk(s) which you want expanding:

PS C:\Windows\system32> Get-Volume

DriveLetter FileSystemLabel FileSystem DriveType HealthStatus OperationalStatus SizeRemaining     Size
----------- --------------- ---------- --------- ------------ ----------------- -------------     ----
E           DATA            NTFS       Fixed     Healthy      OK                     26.88 GB 39.87 GB
D                                      CD-ROM    Healthy      Unknown                     0 B      0 B
            System Reserved NTFS       Fixed     Healthy      OK                    162.88 MB   500 MB
C                           NTFS       Fixed     Healthy      OK                     26.66 GB 39.51 GB

Step 2 – Use Get-PartitionSupportedSize -DriveLetter C to check if and to what size it can be expanded:

PS C:\Windows\system32> Get-PartitionSupportedSize -DriveLetter C

    SizeMin     SizeMax
    -------     -------
13831712768 42423287808

Step 3 – Here we store to $size variable the output from the command in Step 2 and then we resize the partition to its maximum size:

$size = Get-PartitionSupportedSize -DriveLetter C
Resize-Partition -DriveLetter C -Size $size.SizeMax

Step 4 – Result

twitterredditpinterestlinkedinmail

6 Comments to “How To: Resize Disk Partition with PowerShell”

  1. Orlando Paez

    How do i do a query on the drive to see if it is healthy prior to expanding it? What i need to do is see if the Dirty Bit is flagged or not, then continue with patritioning the drive.

    Reply
  2. Rangaraj

    Get-volume and Get-PartitionSupportedSize commandlet you have mentioned is not available in powershell.

    Could you please help me .

    Thank you.

    Reply
    1. Corin Author

      You need at least Powershell version 4. Alternatively you can use WMI – Get-WMIObject -Class Win32_Volume | Select DriveLetter,FreeSpace,Capacity,DeviceID,Label

      Reply

Leave a Comment

Your email address will not be published. Required fields are marked *