Diskpart and PowerShell–part 2: Create a virtual disk

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

Advertisements
This entry was posted in Powershell, Storage. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s