需要使用 Msvm_VirtualSystemManagementService.AddVirtualSystemResources 添加合成磁盘(ResourceType. Disk , ResourceSubType. DiskSynthetic)。Parent = SCSI 控制器的 WMI 路径。
ManagementObject synthetic = Utilities.GetResourceAllocationSettingData(scope,
ResourceType.Disk, ResourceSubType.DiskSynthetic);
synthetic["Parent"] = <ideControllerPath>; //or SCSI controller path (WMI path)
synthetic["Address"] = <diskDriveAddress>; //0 or 1 for IDE
string[] RASDs = new string[1];
RASDs[0] = synthetic.GetText(TextFormat.CimDtd20);
然后使用 Msvm_VirtualSystemManagementService.AddVirtualSystemResources附加虚拟硬盘(ResourceType.StorageExtent ,ResourceSubType.VHD )。Parent = 合成磁盘的 WMI 路径,Connection = *.vhd 文件路径。
ManagementObject hardDisk = Utilities.GetResourceAllocationSettingData(scope,
ResourceType.StorageExtent, ResourceSubType.VHD);
hardDisk["Parent"] = <syntheticPath>; //WMI path
string[] connection = { <vhdPath> }; //Path to *.vhd file
hardDisk["Connection"] = connection;
string[] RASDs = new string[1];
RASDs[0] = hardDisk.GetText(TextFormat.CimDtd20);
使用虚拟化示例和WMI Explorer的通用实用程序。