Powershell Shrink/Extend Volume in Windows Server 2019/2022

by John, Updated on: August 14, 2022

PowerShell is a task-based command-line shell and scripting language built on .NET. PowerShell helps system administrators and power-users rapidly automate tasks that manage operating systems and processes. PowerShell commands let you manage computers from the command line. It includes a rich expression parser and a fully developed scripting language. PowerShell can do so much tasks, then is it possible to resize partition with PowerShell in Windows server? The answer is yes. In this article, I'll introduce how to shrink/extend volume with PowerShell in Windows Server 2019/2022.

How to shrink volume with powershell in Server 2019/2022

Firstly, press Windows + X on the keyboard, then select Windows PowerShell (Admin) in the list.

Steps to shrink volume with PowerShell in Windows Server 2019/2022:

  1. Type diskpart in the command window and press Enter.
  2. Type list volume and press Enter, then you'll see all partitions in a list with some information.
  3. Type select volume D and press Enter. (D is the number or drive letter of the partition that you want to shrink.)
  4. Type shrink desired=YY. (YY is a value in but without MB)

Immediately, PowerShell reports this drive is successfully shrunk.

Powershell shrink

How to extend volume with powershell in Server 2019/2022

If you want to extend partition with PowerShell in Windows server, it is not so easy as shrinking. Firstly, you have to delete the right contiguous partition. If there's no such partition or you cannot delete it, PowerShell cannot help you extend partition.

Powershell to extend volume in Windows Server 2019/2022:

  1. Type diskpart in PowerShell command window and press Enter.
  2. Type select volume D and press Enter. (D is the number or drive letter of the right contiguous partition.)
  3. Type delete volume and press Enter.
  4. Type select volume C and press Enter. (C is the number or drive letter of the partition that you want to expand.
  5. Type extend and press Enter.

Run list volume again, as you see, C drive is extended from 40GB to 110GB.

Extend successfully

Powershell extend

Limitations to resize partition with PowerShell

After running diskpart in PowerShell, run help shrink and help extend, you'll see the restrictions of PowerShell to resize partition in Windows Server 2019/2022.

Shrink limitations

Extend limitations

Limitations to resize partition with PowerShell in Windows Server 2019/2022:

If you run Windows Server 2019 Disk Management to resize partition, there are the same restrictions, so you'd better run server partition software.

Download NIUBI Partition Editor and follow the steps in the video to shrink and extend partition.

How to extend system partition C by shrinking other volume:

Video Server 2019

How to extend D drive by shrinking other partition:

Video Server 2019

Besides shrinking and extending partition in Windows Server 2019/2022 and previous Server 2003/2008/2012/2016, NIUBI Partition Editor helps you do many other disk and partition operations.