Bye-Bye Diskpart: PowerShell Is Moving In!

Meet 3 Windows 8/Windows Server 2012 cmdlets that will save you lots of time

Mark Minasi

June 17, 2013

4 Min Read
Bye-Bye Diskpart: PowerShell Is Moving In!

I’ve been writing a lot of Active Directory (AD) PowerShell columns lately, and I aim to continue, but this month I want to take a break and talk about some truly cool PowerShell cmdlets: the volume cmdlets, the disk cmdlets, and the physicaldisk cmdlets. Why do I love them? They save me time—lots of time. But there’s one wrinkle: They’re available only on Windows 8 and Windows Server 2012. But if you’re working with either OS, you shouldn’t miss these. So here’s a short rundown of three of those valuable commands.

Get-Volume: No Need for Windows Explorer

At least once a day, I need to know what drive letters are free and which I’m using on my system. For ages, I’ve either opened up Windows Explorer or opened Diskpart and typed list volume (or its short version, lis vol). But Explorer requires the mouse, and Diskpart takes time to start up, and that slows me down. If, by contrast, I go to the PowerShell command prompt window—where I get much of my work done anyway—I need only type

get-volume

and I’ll get, among other things, a quick list of all currently used drive letters (well, that and a bunch of other information, but that’s another story).

Set-Partition: Re-lettering Drives without Diskpart

Get-volume has a cousin cmdlet, set-partition, that’s also pretty useful. I’m usually curious about the currently used drive letters because I want to change some partition’s drive letter. For example, on my system VMware Workstation gets cranky if the virtual machines (VMs) that I run aren’t in a folder named VMs on a drive letter of E, and that volume is usually on a second physical drive. But because I have different combinations of storage devices attached on different days, the drive containing the VMs doesn’t always get to be E. (Yes, there is a way to resolve that with mklink, but that too is a story for another day.) As a result, some days my first order of business is to get the E issue straightened out.

It’s not unusual for me to find my VMs folder on, say, drive G, and something else—a USB stick, perhaps—on drive E. The fix isn’t hard (re-letter the USB stick to something like V, freeing up E and enabling me to change the thing currently lettered as G to E). The problem lies in changing a partition’s letter. You know what I mean: I have to fire up either Disk Manager or, worse, Diskpart.

Don’t get me wrong, I love Diskpart. I couldn’t have built my free replacement for Microsoft's SteadyState—which I call SteadierState—as a few batch files without it, but honestly getting anything done with Diskpart always feels like I’m trying to build a mnemonic circuit with just stone knives and bearskins. Its syntax is highly idiosyncratic, reminding me of the weird Cisco IOS look of Netsh (another powerful command-line tool that no one uses because it’s so hard to figure out), and scripting it is a pain.

In contrast, PowerShell cmdlets are a bit long-winded, but they’re easy to read, as in these two, which solve my VMware problem:

set-partition -driveletter E -newdriveletter Vset-partition -driveletter G -newdriveletter E

Those are very nice, and trust me: If you’ve got the PowerShell command prompt already open and remember to use tab completion, you can bang out those three commands (remember that you need a get-volume beforehand) much faster than opening Disk Manager, even with the Windows key + X combination that you can use in Windows 8 and Windows Server 2012.

Get-Disk: More Diskpart Replacement

Many storage-related tasks require knowing not a drive letter but a drive number. Now, of course, in that sentence I (deliberately) made a mistake that we all tend to make: using the words drive or disk to sometimes mean a physical disk and sometimes mean a volume/partition. Most of us would say that we “installed a new drive” and in the next breath might refer to “data on drive G,” where the first phrase refers to an actual physical drive and the second refers to a volume or partition. (Heck, even PowerShell does this. Look at the -driveletter and -newdriveletter parameters.) But here’s one more PowerShell cmdlet that’s worth learning when you’re working with storage, especially if you want to avoid Disk Manager or Diskpart:

get-disk

This cmdlet shows you physical devices (mostly) and their disk numbers—one fewer trip to Diskpart. Give these cmdlets a try, and I think you’ll see what I love about them!

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