header image

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

Posted by: | April 28, 2017 Comments Off on 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

under: PowerShell, Storage

Comments are closed.

Categories