Powershell Command for Disks and Partitions Management
In this article we will learn how to manage disk and delete the disk partition form the disk using the window feature PowerShell and it would be a command line using Window PowerShell
Using the PowerShell we can perform or manage all the local disk and partition same like Window Disk Management ( GUI - diskmgmt.msc )
Relate Posts
How to Open PowerShell ?
To Open PowerShell, Go to Search and type PowerShell See the below screenshot
Window Search ==> Windows PowerShell ==> Run as Administrator
How to Delete the partition from disk on Window Operating System
View Disk Partition detailsPS C:\> diskpartDisk ### Status Size Free Dyn Gpt
DISKPART> list disk
-------- ------------- ------- ------- --- ---
Disk 0 Online 119 GB 2048 KB *
Disk 1 Online 931 GB 0 B *
Here i have two disk ( Disk 0 i have installed OS and Disk 1 is data disk ),We will delete the partition form DATA disk 1.
Here i have two disk ( Disk 0 i have installed OS and Disk 1 is data disk ),We will delete the partition form DATA disk 1.
DISKPART> select disk 1Disk 1 is now the selected disk.
DISKPART> list partitionPartition ### Type Size Offset
------------- ---------------- ------- -------
Partition 1 Primary 500 GB 1024 KB
Partition 2 Primary 431 GB 500 GB
So, We got the disk and partition information, you may read more..
As per the above details, we have two partition on the disk 1, I will delete the partition
and clean the disk
Note: Be carefully, Just keep the data backup before doing anything because this action delete
all the data.
Thanks you !!
So, We got the disk and partition information, you may read more..
As per the above details, we have two partition on the disk 1, I will delete the partition
and clean the disk
Note: Be carefully, Just keep the data backup before doing anything because this action delete
all the data.
Method 1:
Delete Partitions With Command Prompt ( Diskpart command )
DISKPART> select partition 2
Partition 2 is now the selected partition.
Here, I have select the partition 2 from the disk for deletion
DISKPART> delete partition
DiskPart successfully deleted the selected partition.
Delete Partitions With Command Prompt ( Remove-Partition )
Print All the disk
PS C:\> Get-PhysicalDisk
The command will print all the installed disk, here i have two disk ( disk 0 and disk 1 )
PowerShell print all the partitions
PS C:\> Get-Partition -DiskNumber 1
To removes the partition associated with drive letter ( In my case D is the drive latter )
PS C:\>Remove-Partition -DriveLetter D
Type Y or Hit the enter to perform the action
To remove partition number 1 from disk number 1
PS C:\>Remove-Partition -DiskNumber 1 -PartitionNumber 1
- In this Tutorial, I have 2 hard disk, In disk 1 i have installed OS and second disk for data.
- Disk number ( -DiskNumber 1 ) and partition numner ( -PartitionNumber 1 ) can be change if we have more then 2 disk.
- Use this command carefully because your data will be erase
- Take the backup of your drive before preforming any action's
I hope this topic gave you all the information you needed. If you have any further questions or would like more detailed directions feel free to contact us using any of the following sources.We look forward to talking to you.