This is a part of an on-going blog series written by Adam Gordon. Each week, Adam will walk you through a PowerShell command, showing you when and how to use each one. This week, Adam covers Clear-Disk.
When to use Clear-Disk?
The Clear-Disk cmdlet cleans a disk by removing all partition information and un-initializing it, erasing all data on the disk.
If the disk contains active data volumes, then the -RemoveData parameter is required as this will delete all data from the specified disk. This cmdlet will not clear OEM recovery partitions unless –RemoveOEM parameter is also specified.
How to use Clear-Disk?
Clear a blank disk:
Clear-Disk -Number 2
This command clears disk number two only if it does not contain active data volumes and/or OEM partitions.
Clear a disk with data partitions:
Clear-Disk -Number 2 -RemoveData
This command clears the disk if it has data partitions, but not if it also has OEM partitions.
Clear a disk with data and OEM partitions:
Clear-Disk -Number 2 -RemoveData -RemoveOEM
This command clears the disk regardless of whether it contains data or OEM partitions.
Learn last week’s command: Find-Script.
Need PowerShell training? Check out ITProTV’s PowerShell online IT training courses.