Skip to content

Instantly share code, notes, and snippets.

@ksasao
Last active July 1, 2018 01:27
Show Gist options
  • Select an option

  • Save ksasao/0feabd44a72eac18db29682d82ce8f3a to your computer and use it in GitHub Desktop.

Select an option

Save ksasao/0feabd44a72eac18db29682d82ce8f3a to your computer and use it in GitHub Desktop.
Create blank .vhdx virtual disk using PowerShell
$vhdPath="sample.vhdx"
$vhdSize = 20GB
$driveLetter = "E"
$label = "Data"
$fileSystem = "NTFS"
New-VHD -Path $vhdPath -Dynamic -SizeBytes $vhdSize
Mount-VHD -Path $vhdPath
$disk = get-vhd -path $vhdPath
Initialize-Disk $disk.DiskNumber
$partition = New-Partition -UseMaximumSize -DiskNumber $disk.DiskNumber
Format-Volume -NewFileSystemLabel $label -FileSystem $fileSystem -Confirm:$false -Force -Partition $partition
Set-Partition -DiskNumber $disk.DiskNumber -PartitionNumber $partition.PartitionNumber -NewDriveLetter $driveLetter
Dismount-VHD -Path $vhdPath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment