20 C
Texas

How to format USB with PowerShell

It is well known that formatting a USB drive involves completely erasing its contents. Of course, there is a reason for this. Most of the time we do it because of access errors to the device, the presence of viruses, security measures, or malicious manipulation. Generally, we do this process graphically. That is, using the file explorer. Since it is enough to make the right click of the mouse on the device and to give the order to format. However, sometimes the system does not allow to perform the task. Perhaps you did not know that this can be done through the command line. Stay with us to learn how to format a USB with PowerShell.

How to format a USB drive using PowerShell

The first thing you have to do is to open a PowerShell with administrator privileges. With this in mind, press the Win+X combination. Next, select the corresponding option.

Opening a PowerShell with administrator privileges
Opening a PowerShell with administrator privileges

Then, you must use the following syntax:

Format-Volume -DriveLetter -FileSystem -NewFileSystemLabel 
- Advertisement -

Please note that the parameters are as follows:

  • In the -DriveLetter line, enter the letter assigned by the system to the USB.
  • In the -FileSystem line please assign the format to set (NTFS, FAT32, etc).
  • NewFileSystemLabel allows you to add a label to the USB flash drive.

In our example, the command would look like this:

Format-Volume -DriveLetter F -FileSystem NTFS -NewFileSystemLabel Osradar
Forming a USB device with PowerShell
Forming a USB device with PowerShell

At the end of the process, a message like this will be displayed.

How to perform low-level formatting with PowerShell

It is also possible to perform a low-level formatting. That is, a more complete task that takes more time. However, it allows to erase more complete sectors of the USB drive. Please use the following syntax:

Format-Volume -DriveLetter -FileSystem -Full -Force

See the image for a particular example:

Formatting a usb device at low level.
Formatting a usb device at low level.

After a while, we will see a window similar to the previous one.

Other operations available from PowerShell. Erasing the contents of the USB flash drive.

We can also perform other operations from the console. In this opportunity we will erase the content of the USB memory. With this in mind, from the PowerShell with administrator privileges please run the following command:

Get-Disk

This command shows a list of available disks. This command shows a list of available disks. In this case, the USB flash drive has the number 2 assigned to it. Consequently, we will erase the data from the disk using its number:

Get-Disk 2 | Clear-Disk -RemoveData

Please note that the number may be different on your computer. Please press Y to confirm the operation.

Erasing the contents of the USB flash drive.
Erasing the contents of the USB flash drive.

Now let’s create the new partition on the USB with the command:

New-Partition -DiskNumber 2 -UseMaximumSize

With this command we have assigned the maximum capacity of the USB flash drive.

Next we will apply a quick format with the desired file system:

Get-Partition -DiskNumber 2 | Format-Volume -FileSystem NTFS -NewFileSystemLabel Osradar

Finally, we are going to assign the letter to the USB:

Get-Partition -DiskNumber 2 | Set-Partition -NewDriveLetter D

You can notice how the system now recognizes the USB flash drive. To check it, just go to file explorer

Okay, so we have seen how to format a USB flash drive with PowerShell. It is an option to properly clean these devices. Goodbye!

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article