This article introduces how to resize partition with powershell in Windows Server 2019, run powershell to shrink and extend partition volume without losing data.
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? The answer is yes. In this article, I'll show you how to shrink and extend partition with PowerShell in Windows Server 2019.
How to shrink partition volume with PowerShell
Firstly, press Windows and X on the keyboard, then select Windows PowerShell (Admin) in the list.
Steps to shrink partition/volume with PowerShell in Windows Server 2019:
- Type diskpart in the command window and press Enter.
- Type list volume and press Enter, then you'll see all partitions in a list with some information.
- Type select volume D and press Enter. (D is the number or drive letter of the partition that you want to shrink.)
- Type shrink desired=YY. (YY is a value in but without MB)
Immediately, PowerShell reports this drive is successfully shrunk.
How to extend volume partition with PowerShell
If you want to extend partition with PowerShell, it is not so easy as shrinking. Firstly, you have to delete the right contiguous partition. If there's no or you cannot delete this partition, PowerShell cannot help you extend partition.
Steps to extend partition with Powershell in Windows Server 2019:
- Type diskpart in PowerShell command window and press Enter.
- Type select volume D and press Enter. (D is the number or drive letter of the right contiguous partition.)
- Type delete volume and press Enter.
- Type select volume C and press Enter. (C is the number or drive letter of the partition that you want to expand.
- Type extend and press Enter.
Run list volume again, as you see, C drive is extended from 40GB to 110GB.
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.
Limitations to resize partition volume with PowerShell on Windows Server 2019:
- Only NTFS and RAW (without file system) partitions can be shrunk and extended.
- Free (Unallocated) space can only be made on the right when shrinking a partition.
- When extending a partition, there must be contiguous free (Unallocated) space on the right and on the same disk.
- It cannot help you extend a partition by shrinking another one, you must delete the right contiguous volume.
Download NIUBI Partition Editor and follow the steps in the video to shrink and extend partition.
Besides shrinking and extending partitions, it helps you do many other disk and partition operations.