PowerShell Commands for Working with Hard Disk

PowerShell Commands for Working with Hard Disk

PowerShell Commands for Working with Hard Disk. PowerShell commands for working with the hard disk, like the other PowerShell commands that we explained to you in the Powershell tutorial, have a uniform structure.

In CMD, you must use external commands such as Diskpart to use commands that are not in the Command Prompt kernel. But given the power and evolution of PowerShell in Windows, you will have all the commands available with one structure.

In this article, we want to acquaint you with PowerShell commands for working with hard disk so that you can use it to manage and partition all storage devices such as USB Flash Disk, Hard Disk, SD Card, etc.

 

Choose your perfect Windows Virtual Private Server Packages in Eldernode

 

In this article, in order to be useful and understand the instructions for working with hard disks, we will explain in a complete scenario:

The parts of this scenario are:

1- Remove all information and partitioning from a Flash

2- Redistribute it

3- Format and assign a name and Drive Letter to it

 

PowerShell commands for working with hard disk

1- First, open PowerShell with Administrator access.

2- Then enter the following command to get the information of the hard disks connected to the system:

Get-Disk

As you can see in the image below, by entering the above command, complete information of the connected hard disks will be displayed for you:

 

PowerShell commands for working with hard disk

 

3- Then enter the following command to delete the data and partition on the desired disk.

Clear-Disk -Number 3 -RemoveData

 

By entering the above command, you have instructed PowerShell to select the disk with the -number 3 specified in the Get-Disk section and delete all its information.

After executing the command, PowerShell will ask you to confirm the deletion of all data and the selected disk partition, which you will allow operation by entering Y.

 

PowerShell commands for working with hard disk

 

4- After deleting all the information from the flash, we enter the following command to create a new partition:

New-Partition -DiskNumber 3 -UseMaximumSize -IsActive -DriveLetter S

 

The above command creates a partition with the maximum size for disk one and activates it and assigns the letter S to it.

 

PowerShell commands for working with hard disk

 

Note: If you plan to make your hard disk or flash drive smaller in size, just use the phrase -Size 1GB instead of -UseMaximumSize to create a partition of the desired size. Note that instead of 1GB you will be able to enter any amount in the range of your hard disk space.

 

Example of making a partition of any size

New-Partition -DiskNumber 3 -Size 1GB -IsActive -DriveLetter S

 

5- In the end, you must format the created partition by entering the following command:

Format-Volume -DriveLetter S -FileSystem NTFS - NewFileSystemLabel USBDISK

 

After entering the above command, the flash name will be renamed to USBDISK and will be formatted with the NTFS file system.

 

PowerShell commands for working with hard disk

 

That way, with the Get-Disk, Clear-Disk, New-Partition, and Format-Volume commands, you can have complete control over your hard drives with the PowerShell commands.

 

Also, see:

Introduction to Windows PowerShell

Learn important PowerShell commands

How to download files in PowerShell

 

Dear user, we hope you would enjoy this tutorial, you can ask questions about this training in the comments section, or to solve other problems in the field of Eldernode training, refer to the Ask page section and raise your problem in it as soon as possible. Make time for other users and experts to answer your questions.

Goodluck.

 

Use of this Site is subject to express terms of use. By using this site, you signify that you agree to be bound by these