Managing Disks with Powershell

In Powershell version 3.0 which is found in Server 2012 and Windows 8 you are able to manage hard drives entirely from Powershell. This means you are able to add, initialize, format and name disks entirely from the command line. (Even in one line if you so wished)

In this blog entry I am going to run through:

  • How to get disks that have a raw partition format
  • Initialize the disk
  • Create partitions on the disk
  • Format the volume to the desired File system format

To get started we need to get a list of all the disks in the system that have no file system format. To do this we use the following Powershell command.

This will return a table formatted list of disks connected to you system that currently have no file system format.

GetRawDisks

Now that we have a list of disks we can initialize them to the desired partition style. To do this we need to use the Initialize-Disk command.

InitializeDisk

If you run a Get-Disk command after this you will see that the Partition Style has changed from RAW to MBR or GPT.

Now that the disk is initialized we need to create a partition on it. To do this we can use the New-Partition command. By using the -AssignDriveLetter parameter we will get windows to assign the next available drive letter to the new partition. In this case we are using the -UseMaximumSize to create a partition that will fill the size of the disk. You are able to use the -Size command instead to allow for the creation of multiple partitions on the one disk.

NewPartition

All that remains now is to format the newly created partition to the desired file system format. To do this we use the Format-Volume command. You have the option of formatting the disk as exFATFATFAT32NTFS and ReFS. We are going to use NTFS in this case. You are also able to set drive labels at this point.

FormatVolume

At this point you now have a fully formatted and partitioned disk that is accessible in windows.

Now that we know what each part does we can string all the commands together. This is done by using the -PassThru command and the piping character |.

OneLine

I hope this will help you to work smarter not harder! NP

Nathan Payne

I have a passion for all things IT. Whether its the latest tablet or phone all the way through to pioneering cloud computing. In my spare time I like to keep myself busy with Cycling and Photography.

Leave a Reply

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