Today I just added an old SSD to a Windows machine to use it as a back up drive. With old disks, usually they come with existing data, and I wanted to get rid of it. The problem is I couldn’t figure out how to do this using the Disk Management, the native GUI application used to manage disks.

The problem could be simple to Windows users. Basically, when I right-clicked on the 2 partitions (450 MB and 100 MB) on Disk 0, there is no option to remove them.

So I turned to google and looked up how to do this using Windows PowerShell instead. Here is how to delete disk partitions on a Windows machine using PowerShell [1].

  1. List all disks attached to the machine:
PS C:\Users\kenno> Get-Disk

Number Friendly Name Serial Number                    HealthStatus         OperationalStatus      Total Size Partition
                                                                                                             Style
------ ------------- -------------                    ------------         -----------------      ---------- ----------
1      PM991 NVMe... 3530_3930_4E90_1131_0025_3846... Healthy              Online                  476.94 GB GPT
0      Samsung SS... S21MNXAG919148N                  Healthy              Online                  232.89 GB GPT
  1. I wanted to delete existing partitions from Disk 0. First, let’s list all partitions of Disk 0.
PS C:\Users\kenno> Get-Partition -DiskNumber 0


   DiskPath: \\?\scsi#disk&ven_samsung&prod_ssd#4&2e0052d9&0&000000#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}

PartitionNumber  DriveLetter Offset                                        Size Type
---------------  ----------- ------                                        ---- ----
1                           1048576                                     450 MB Recovery
2                           472907776                                   100 MB System
3                           577765376                                    16 MB Reserved
  1. Great. Let’s delete partition number 1 of Disk 0.
PS C:\Users\kenno> Remove-Partition -DiskNumber 0 -PartitionNumber 1

Confirm
Are you sure you want to perform this action?
This will erase all data on disk 0 partition 1.
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
  1. Verify if the partition 1 has been deleted.
PS C:\Users\kenno> Get-Partition -DiskNumber 0


   DiskPath: \\?\scsi#disk&ven_samsung&prod_ssd#4&2e0052d9&0&000000#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}

PartitionNumber  DriveLetter Offset                                        Size Type
---------------  ----------- ------                                        ---- ----
2                           472907776                                   100 MB System
3                           577765376                                    16 MB Reserved
  1. Great! Repeat step 3 for partitions 2 and 3 of Disk 0.

  2. Finally, let’s list the partitions of Desk 0 again.

PS C:\Users\kenno> Get-Partition -DiskNumber 0
Get-Partition : No MSFT_Partition objects found with property 'DiskNumber' equal to '0'.  Verify the value of the
property and retry.
At line:1 char:1
+ Get-Partition -DiskNumber 0
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (0:UInt32) [Get-Partition], CimJobException
    + FullyQualifiedErrorId : CmdletizationQuery_NotFound_DiskNumber,Get-Partition

So that’s it. If I were a Windows system administrator, I think PowerShell would be an indispensable tool, and have no excuse to get very good with it.

Bonus:

As I mentioned earlier, my intention is to use the secondary disk as a backup disk. Therefore, I will still need to create a new volume on it after removing all existing partitions. At this stage, I can use the Disk Management tool to create a new simple volume by right-clicking on the “Unallocated” space of Disk 0. However, let’s do this using PowerShell command too. Details information can be found at [2].

PS C:\Users\kenno> New-Partition -DiskNumber 0 -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel Data


DriveLetter FriendlyName FileSystemType DriveType HealthStatus OperationalStatus SizeRemaining      Size
----------- ------------ -------------- --------- ------------ ----------------- -------------      ----
            Data         NTFS           Fixed     Healthy      OK                    232.79 GB 232.88 GB

Here is the new partition created on Disk 0.

PS C:\Users\kenno> Get-Partition -DiskNumber 0


   DiskPath: \\?\scsi#disk&ven_samsung&prod_ssd#4&2e0052d9&0&000000#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}

PartitionNumber  DriveLetter Offset                                        Size Type
---------------  ----------- ------                                        ---- ----
1                           1048576                                  232.88 GB Basic

Note: I just realized that I could have performed a different operation to remove all existing partitions on a disk in few PowerShell commands after reading guide from link [2]. Oh well, it doesn’t matter, ‘cuz in the end I still got a new volume (data) created, and get to learn a few tricks with PowerShell.

References: