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. This article introduces 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:
- 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.
Note: only NTFS partition is supported.
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:
- 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/2022.
Limitations to resize partition with PowerShell in Windows Server 2019/2022:
- Only NTFS and RAW (without file system) partitions can be shrunk and extended.
- Unallocated space can only be made on the right when shrinking a partition.
- When extending a partition, there must be contiguous 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.
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.
Besides shrinking and extending partition in Windows Server 2019/2022 and previous Server 2003/2008/2012/2016, this partition editor helps you do many other disk and partition management operations.