PowerShell:使用 DiscUtils 创建和初始化虚拟磁盘

PowerShell: Create and Initialize a virtual disk with DiscUtils

使用 .NET DiscUtils PowerShell Module 时,出现以下错误:

Import-Module DiscUtils.psd1
New-VirtualDisk hd.vhd -Type VHD-dynamic -Size 500MB
Initialize-VirtualDisk hd.vhd -VolumeManager Bios

Initialize-VirtualDisk : Path specified is not a virtual disk

hd.vhd 有效,如果用其他工具挂载,Windows 磁盘管理可以识别。

刚刚找到正确的方法:

Import-Module DiscUtils.psd1
New-VirtualDisk hd.vhd -Type VHD-dynamic -Size 500MB
New-PSDrive vhd -PSProvider virtualdisk -Root hd.vhd -ReadWrite
Initialize-VirtualDisk vhd: -VolumeManager Bios

随后可以对驱动器进行分区和格式化。
要格式化前 250MB NTFS:

New-Volume vhd: -Size 250MB -Type WindowsNtfs
Format-Volume vhd:\Volume0 -Filesystem Ntfs -Label "virtdrive"