Diskpart and PowerShell–part 3: Initialize disk and create volume

Last time we created a virtual disk and mounted it. In this post we’ll initialize the disk and create a volume.

Start by remounting the disk

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

You can now initialize the disk:

Initialize-Disk -Number 1

Create a partition:

New-Partition -DiskNumber 1 -DriveLetter F –UseMaximumSize

Ignore the message about formatting as you want to control that:

Format-Volume -DriveLetter F -FileSystem NTFS -Confirm:$false –Force

Your new disk is ready to use.

The diskpart equivalents can be found here: https://technet.microsoft.com/en-us/library/cc766465(v=ws.10).aspx

You can perform the creation and formatting of the disk in one pass:

New-VHD -Path C:\test\Test2.vhdx -Dynamic -SizeBytes 10GB |
Mount-VHD -Passthru |
Initialize-Disk -PassThru |
New-Partition -DriveLetter G -UseMaximumSize |
Format-Volume -FileSystem NTFS -Confirm:$false –Force

Parameterize the path, size and drive letter and you have a handy function to set up disks

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