Disks and Partitions Management with Windows PowerShell

In this text we’ll look on the disk, partition and quantity administration from PowerShell console. You can carry out from PowerShell all of the operations of managing native disks and partitions, that you’re used to acting from the “Disk Management” GUI (diskmgmt.msc) or from the diskpart.exe command line software. Disk administration cmdlets are included within the Storage module out there in PowerShell three.zero. We’ll think about initialize a disk, create a partition desk on it, create a quantity and format it. The instructions given beneath will work in Windows 10 / Server 2016 and Windows eight.1 / Server 2012 R2 (for earlier Windows variations you’ll have to replace PowerShell first).

There are 160 PowerShell cmdlets within the Storage module in Windows 10. To show all out there instructions associated to disk administration, run the next command:

Get-Command -Module Storage

local storage (disk, partition)management module in windows powershell

Important. Be very cautious when managing disks and partitions from PowerShell so as to not unintentionally delete or format a partition containing information.

PowerShell: List Local Disks and Partitions

First of all, attempt to show the checklist of native disks out there in your system on the logical stage. To do it, run this command:

Get-Disk | ft -AutoSize

To choose solely the system disk on which Windows is put in, enter the next command:

Get-Disk | Where-Object IsSystem -eq $True | fl

As you possibly can see, the command has returned the next attributes of the system disk (you should utilize them within the choice as effectively):

Number : zero
Path : ?scsi#disk&ven_vmware&prod_virtual_disk#5&1ec42ba7&zero&000000#
Manufacturer : VMware
Model : Virtual disk
SerialNumber :
Size : 98 GB
AllottedSize : 98432321434
LogicalSectorSize : 512
PhysicalSectorSize : 512
NumberOfPartitions : 2
PartitionStyle : MBR
IsReadOnly : False
IsSystem : True
IsBoot : True

You can show Offline disks solely:

Get-Disk | Where-Object IsOffline –Eq $True| ft –AutoSize

powershell Get-Disk offline and system

If you want the details about bodily disks (the traits and standing of bodily disks on a pc), use Get-BodilyDisk cmdlet (beforehand we confirmed detect a utilizing Get-BodilyDisk cmdlet and use it then configure a fault tolerant ).

Get-PhysicalDisk info from powershell

You can detect the kind of related disk: SSD, HDD (often related over SATA bus) or a USB flash drive (UnSpecified media kind).

DeviceId Model                      MediaType   BusType         Size

——— ——                      ———   ——-         —-

zero        TOSHIBA MK3775VSXP         HDD         SATA    500156374016

1        Samsung SSD 840 PRO Series SSD         SATA    128060514304

2        Transcend                 UnSpecified USB     128169757184


You can show the checklist of partitions on all disks:


Or partitions on the desired disks solely:

Get-Partition –DiskNumber 1,2

To show the checklist of all volumes in Windows, run this command:


Get-Volume cmdlet

Please be aware that the disk numbering begins from zero, and partition numbering – from 1.

Disk Initialization in PowerShell

In the earlier instance you may have seen that one of many disks is Offline and has a RAW label within the Partition Style column. Let’s attempt to initialize it, create a GPT or MBR partition desk and create a brand new partition on it.

First of all, it’s essential to get the disk Online:

Get-Disk | Where-Object IsOffline –Eq $True | Set-Disk –IsOffline $False

Now you possibly can initialize it (its index is 1):

Initialize-Disk -Number 1

Get-Disk online and Initialize-Disk in powershell

By default, a GPT (GUID) partition desk is created on a disk, however for those who want an MBR one, run this command:

Initialize-Disk 1 –PartitionStyle MBR

If there are some information on the disk, you possibly can change the partition desk from MBR to GPT with out eradicating the information utilizing the software.

In order to not specify the disk quantity, you possibly can initialize all disks with the RAW partition desk:

Get-Disk | Where-Object PartitionStyle –Eq 'RAW' | Initialize-Disk

Please be aware disk might have the RAW standing when the partition desk is corrupted. You can attempt to get better the partition desk and information in your RAW disk .

How to Create Partitions on a Disk?

To create a brand new partition on a disk, the New-Partition cmdlet is used. Let’s create a 10 GB partition and assign the letter L: to it:

New-Partition –DiskNumber 1 -Size 10gb -DriveLetter L

create disk partition with powershell

If you need the partition to occupy all out there disk house, use the UseMaximumSize attribute. To assign a letter robotically, the AssignDriveLetter parameter is used ().

New-Partition –DiskNumber 1 -AssignDriveLetter –UseMaximumSize

You can change the assigned letter utilizing this command:

Set-Partition –DriveLetter L -NewDriveLetter U

If you need to broaden the prevailing partition, to begin with show the out there unallocated house to increase this partition:

Get-PartitionSupportedSize -DriveLetter L | Format-List

Then you possibly can prolong the dimensions of the partition to the utmost:

$MaxSize = (Get-PartitionSupportedSize -DriveLetter L).SizeMax
Resize-Partition -DriveLetter L -Size $MaxSize

Resize-Partition from posh

If you need to make a partition energetic, this command is used:

Set-Partition -DriveLetter U -IsActive $true

Formatting a partition with PowerShell

Let’s format new partition within the NTFS and set the DBData quantity label:

Format-Volume -DriveLetter L -FileSystem NTFS -NewFileSystemLabel DBData -Confirm:$false


How to Remove Partitions from a Disk?

To take away all partitions on disks 1 and 2 with out affirmation, run this command:

Get-Partition –DiskNumber 1,2 | Remove-Partition -Confirm:$false


To delete all partitions from disks and fully clear information, run the command

Clear-Disk -Number 1 -RemoveInformation -Confirm:$false

If there are OEM partitions on a disk (, , ), use the RemoveOEM parameter to take away them:

Clear-Disk -Number 1 -RemoveInformation –RemoveOEM

The subsequent PowerShell one-liner will initialize all new related RAW-type disks, create the partition desk on them and create an NTFS partitions with the utmost out there dimension. It is handy to make use of it when connecting a brand new disk:

Get-Disk |Where-Object PartitionStyle -eq 'RAW' |Initialize-Disk -PartitionStyle MBR -PassThru |New-Partition -AssignDriveLetter -UseMaximumSize |Format-Volume -FileSystem NTFS -Confirm:$false

Check Also

How to Backup Active Directory Domain Controller?

In this text we’ll speak about Active Directory area controller backup and find out how …

Leave a Reply

Your email address will not be published. Required fields are marked *