PowerShell for Windows Admins

Apr 27 2017   1:44PM GMT

Diskpart and PowerShell–part 2: Create a virtual disk

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Tags:
Disk storage
Powershell

Before we start digging into the diskpart/Storage module functionality we need a disk to practice on. I don’t recommend using your machine’s system disk – bad things will happen.

The Hyper-V module has  a New-VHD cmdlet so lets use that to create a disk to play with. The great thing about virtual disks is that you can delete then if everything goes horribly wrong.

There is a New-VirtualDisk cmdlet in the storage module but that works with storage pools. We’ll cover that later in the series.

Lets create a virtual disk:

New-VHD -Path C:\test\Test1.vhdx -Dynamic -SizeBytes 10GB

You can access the virtual disk using the path

Get-VHD -Path C:\test\Test1.vhdx

You need to mount the virtual disk before you can work with it

Get-VHD -Path C:\test\Test1.vhdx | Mount-VHD

Once mounted you can use get-Disk to identify the virtual disk

PS> Get-Disk | select Number, FriendlyName, PartitionStyle

Number FriendlyName               PartitionStyle
------ ------------               --------------
     1 Msft Virtual Disk          RAW
     0 Samsung SSD 840 PRO Series MBR

The clue is in the friendly name and that the partition style is RAW.

Next time we’ll look at formatting and partitioning the new drive. For now we’ll just dismount the virtual disk

Dismount-VHD -DiskNumber 1

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: