PowerShell Disk Management: How to Initialize, Partition a Disk

In this video, you learn how to use PowerShell to initialize a disk.

Brien Posey

August 10, 2022

4 Min Read
PowerShell Disk Management: How to Initialize, Partition a Disk
Getty Images

The following is a transcript of the above video, which walks through the PowerShell disk management process of initializing a disk.

Brien Posey:  Hi, I'm Brien Posey. In this video, I'm going to show you how to use PowerShell to initialize a disk on a Windows 10 system.

So, right now I'm logged into a Windows 10 PC. What I'm going to do is right-click on the Start button, and I'll go to Run. I'm going to type diskmgmt.msc and click OK. That's going to open up the Disk Management Console.

The reason why I want to open this console is just to show you that we have a disk that's attached to this system that hasn't been initialized yet. You can see that I'm getting a message saying that you must initialize a disk before Logical Disk Manager can access it. I'm going to go ahead and cancel out of this because I want to use PowerShell to initialize the disk. I just wanted to show you what the system currently looks like before I open up PowerShell. So, I'll go ahead and click cancel.

You can see my new disk right here. We have 127 GBs of unallocated space on a disk that is not initialized. Let me go ahead and close this out.

Disk Configuration

Now I'm going to open an elevated PowerShell session. So, I'll click on the Start button, and I'll go to All Apps. I'll expand Windows PowerShell, right-click on Windows PowerShell, and run as administrator.

Related:How to Learn PowerShell in 2022

Okay, so here we are in PowerShell. The very first thing that I want to do is to take a look at the disk configuration on this machine. So, I'm going to go ahead and type a command. I'll type Get-Disk – that's the PowerShell cmdlet that retrieves information about the disks that are attached to a system. Then I'm going to pipe that into Select-Object number, model size, health status, operational status, and partition style. I'll press Enter.

We can see that this PC has two different disks. So, we have Disk 0. That's listed first. This is a virtual disk. Both of these are virtual disks. I'm working on a Hyper V virtual machine. And we can see the disk size, we can see that it's healthy, and we can see that this particular disk is formatted GPT and is currently online.

Now, if you look at Disk 1 down here near my mouse pointer, you can see that it's also healthy, and, right now it's online but configured with a RAW partition. So, we need to change that.

The important thing that we're taking away from this particular screen is that the disk that we need to work on is Disk 1.

Initialize the Disk

The next thing that we have to do is bring [Disk 1] online. Actually, the disk is already online, but we'll pretend that it's not because I'm going to show you how to bring the disk online.

So, to do that, I'm going to type Get-Disk, then -Number 1 as a way of indicating that we are working with Disk 1. Then I'm going to use the Set-Disk cmdlet to set the offline status to $False, thereby bringing the disk online. I'll go ahead and press Enter. So, now our disk should be online.

The next thing that we have to do is to initialize the disk. I'm going to do that by typing Initialize-Disk, and then I'll set the number parameter to 1, indicating that we're still working with Disk 1. And we're going to set the partition style to GPT. I'll press Enter.

Now we need to create a partition on the disk. For that, I'm going to use the New-Partition cmdlet.

So, I'm going to type New-Partition -DiskNumber 1, and then I'm going to set the drive letter to F. We could use any drive letter that isn't currently taken. But I'm just going to go with F. And then I'm going to specify the UseMaximumSize parameter as a way of telling PowerShell that we want to use all the available disk space for this partition. I'll press Enter.

You can see the results of the operation. We now have a PartitionNumber 2 and DriveLetter F, and we can see that this is set to 126.98 GBs.

And so, the last thing that we have to do is to format the volume that we just created. To do that, I am going to type Format-Volume, -DriveLetter F, and I'm going to set the file system to NTFS. I'll press Enter. And you can see that the disk is being formatted.

If I open up File Explorer and go to This PC, we now have disk F ready to use, fully provisioned with PowerShell. So, that's how you use PowerShell to provision a new disk.

What PowerShell disk management tips are looking for? Let us know in the comments!

About the Author

Brien Posey

Brien Posey is a bestselling technology author, a speaker, and a 20X Microsoft MVP. In addition to his ongoing work in IT, Posey has spent the last several years training as a commercial astronaut candidate in preparation to fly on a mission to study polar mesospheric clouds from space.

http://brienposey.com/

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like