Powershell – Cannot initialize disk in PowerShell : Initialize-Disk throws “The disk has already been initialized”

hard drivepartitionpowershellusb-flash-drive

I'm trying to change the flash drive's partition style to GPT using PowerShell, but the cmdlet throws "The disk has already been initialized" (even though I've cleaned the drive):

PS C:\WINDOWS\system32> Clear-Disk 5 -RemoveData -RemoveOEM

PS C:\WINDOWS\system32> Get-Disk 5

Number Friendly Name                            OperationalStatus                          Total Size Partition Style          
------ -------------                            -----------------                          ---------- ---------------          
5      UFD 2.0 Silicon-Power16G USB Device      Online                                       15.14 GB MBR     

PS C:\WINDOWS\system32> Initialize-Disk 5 -PartitionStyle GPT
Initialize-Disk : The disk has already been initialized.
At line:1 char:1
+ Initialize-Disk 5 -PartitionStyle GPT
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (StorageWMI:ROOT/Microsoft/Windows/Storage/MSFT_Disk) [Initialize-Disk], CimException
    + FullyQualifiedErrorId : StorageWMI 41001,Initialize-Disk

How can I de-initialize the disk so that I can re-initialize it?

P.S. -PartitionStyle MBR shows the same error.

Best Answer

Clear-Disk does not uninitialize removable media, only disks (HDD, SSD, VHD, etc.). To change the partition style of a removable medium, you can use Set-Disk with the -PartitionStyle parameter:

Set-Disk -Number 5 -PartitionStyle MBR

To view an example on how you can use Set-Disk inside a pipeline, you can have a look at my question on SO.