1

我已经下载了 DDCTK-H SCVMM 2012 Samples并稍微修改了 wcf 项目以使用 SCVMM 2012 的全部功能。

我的目的是从现有的 vhd 创建一个 vm。现在我可以创建一个虚拟机,但我无法成功创建一个带有硬盘的虚拟机。现在我放弃尝试用现有的 vhd 来做这件事,并想用空的 IDE 硬盘创建一个 vm。

我尝试在 SCVMM 2012 的 Virtual Manager Console 上创建一个具有现有独立 vhd 的 vm。为此有一个向导,最后通过单击“查看脚本”,您可以查看此作业所需的所有脚本。

New-SCVirtualScsiAdapter -VMMServer localhost -JobGroup 10a46201-6b94-493f-b402-1e2b46911580 -AdapterID 7 -ShareVirtualScsiAdapter $false -ScsiControllerType DefaultTypeNoType 

New-SCVirtualDVDDrive -VMMServer localhost -JobGroup 10a46201-6b94-493f-b402-1e2b46911580 -Bus 1 -LUN 0 

New-SCVirtualNetworkAdapter -VMMServer localhost -JobGroup 10a46201-6b94-493f-b402-1e2b46911580 -MACAddressType Dynamic -Synthetic -EnableVMNetworkOptimization $false 

Set-SCVirtualCOMPort -NoAttach -VMMServer localhost -GuestPort 1 -JobGroup 10a46201-6b94-493f-b402-1e2b46911580 

Set-SCVirtualCOMPort -NoAttach -VMMServer localhost -GuestPort 2 -JobGroup 10a46201-6b94-493f-b402-1e2b46911580 

Set-SCVirtualFloppyDrive -RunAsynchronously -VMMServer localhost -NoMedia -JobGroup 10a46201-6b94-493f-b402-1e2b46911580 

$CPUType = Get-SCCPUType -VMMServer localhost | where {$_.Name -eq "3.60 GHz Xeon (2 MB L2 cache)"}

New-SCHardwareProfile -VMMServer localhost -CPUType $CPUType -Name "Profile865cc017-4009-4ab3-9b58-0210f1d70daa" -Description "Profile used to create a VM/Template" -CPUCount 1 -MemoryMB 512 -DynamicMemoryEnabled $false -MemoryWeight 5000 -VirtualVideoAdapterEnabled $false -CPUExpectedUtilizationPercent 20 -DiskIops 0 -CPUMaximumPercent 100 -CPUReserve 0 -NumaIsolationRequired $false -NetworkUtilizationMbps 0 -CPURelativeWeight 100 -HighlyAvailable $false -DRProtectionRequired $false -NumLock $false -BootOrder "CD", "IdeHardDrive", "PxeBoot", "Floppy" -CPULimitFunctionality $false -CPULimitForMigration $false -JobGroup 10a46201-6b94-493f-b402-1e2b46911580 

New-SCVirtualDiskDrive -VMMServer localhost -IDE -Bus 0 -LUN 0 -JobGroup 10a46201-6b94-493f-b402-1e2b46911580 -VirtualHardDiskSizeMB 40960 -Dynamic -Filename "aaa_disk_1" -VolumeType BootAndSystem 

$HardwareProfile = Get-SCHardwareProfile -VMMServer localhost | where {$_.Name -eq "Profile865cc017-4009-4ab3-9b58-0210f1d70daa"}

New-SCVMTemplate -Name "Temporary Template94a74fb9-9cab-4e22-b653-91c5778732cb" -HardwareProfile $HardwareProfile -JobGroup 10a46201-6b94-493f-b402-1e2b46911580 -NoCustomization 

$template = Get-SCVMTemplate -All | where { $_.Name -eq "Temporary Template94a74fb9-9cab-4e22-b653-91c5778732cb" }
$virtualMachineConfiguration = New-SCVMConfiguration -VMTemplate $template -Name "aaa"
Write-Output $virtualMachineConfiguration
$cloud = Get-SCCloud -Name "MyVMCloud"
New-SCVirtualMachine -Name "aaa" -VMConfiguration $virtualMachineConfiguration -Cloud     $cloud -Description "bbb" -JobGroup "10a46201-6b94-493f-b402-1e2b46911580" -ReturnImmediately -StartAction "NeverAutoTurnOnVM" -StopAction "SaveVM"

使用这些 ps 脚本,我可以创建一个带有空硬盘的虚拟机;这对我来说很酷。所以我试图简化脚本,因为我不想在 DDCTK-H 示例中实现 SCVMM 2012 的全部功能。

public interface IManagementService
{
    VirtualDiskDriveInfo NewVirtualDiskDriveFromAnyHostDiskToJobGroup(string scvmmServerName, int port, bool anyStorageDisk, byte bus, VHDBusTypeInfo busType, byte lun, Guid jobGroup, bool bootVolume = false, string jobVariable = null, Guid proTipID = default(Guid), bool returnImmediately = false, bool runAsynchronously = false, Guid storageClassificationID = default(Guid), bool systemVolume = false, VolumeTypeInfo volumeType = VolumeTypeInfo.None);
    VirtualDiskDriveInfo NewVirtualDiskDriveFromAnyHostDiskToTemplate(string scvmmServerName, int port, bool anyStorageDisk, byte bus, VHDBusTypeInfo busType, byte lun, Guid VMTemplateID, bool bootVolume = false, string jobVariable = null, Guid proTipID = default(Guid), bool returnImmediately = false, bool runAsynchronously = false, Guid storageClassificationID = default(Guid), bool systemVolume = false, VolumeTypeInfo volumeType = VolumeTypeInfo.None);
    VirtualDiskDriveInfo NewVirtualDiskDriveFromExistingHostVHDToVM(string scvmmServerName, int port, byte bus, VHDBusTypeInfo busType, byte lun, string fileName, string path, bool useLocalVirtualHardDisk, Guid vmID, Guid jobGroup = default(Guid), bool bootVolume = false, string jobVariable = null, Guid proTipID = default(Guid), bool returnImmediately = false, bool runAsynchronously = false, Guid storageClassificationID = default(Guid), bool systemVolume = false, VolumeTypeInfo volumeType = VolumeTypeInfo.None);
    VirtualDiskDriveInfo NewVirtualDiskDriveFromExistingVHDToJobGroup(string scvmmServerName, int port, byte bus, VHDBusTypeInfo busType, byte lun, Guid virtualHardDiskID, Guid jobGroup, bool bootVolume = false, string jobVariable = null, Guid proTipID = default(Guid), bool returnImmediately = false, bool runAsynchronously = false, Guid storageClassificationID = default(Guid), bool systemVolume = false, VolumeTypeInfo volumeType = VolumeTypeInfo.None);
    VirtualDiskDriveInfo NewVirtualDiskDriveFromExistingVHDToTemplate(string scvmmServerName, int port, byte bus, VHDBusTypeInfo busType, byte lun, Guid virtualHardDiskID, Guid vmTemplateID, bool bootVolume = false, string jobVariable = null, Guid proTipID = default(Guid), bool returnImmediately = false, bool runAsynchronously = false, Guid storageClassificationID = default(Guid), bool systemVolume = false, VolumeTypeInfo volumeType = VolumeTypeInfo.None);
    VirtualDiskDriveInfo NewVirtualDiskDriveFromExistingVHDToVM(string scvmmServerName, int port, byte bus, VHDBusTypeInfo busType, byte lun, Guid virtualHardDiskID, Guid vmID, bool bootVolume = false, string jobVariable = null, Guid proTipID = default(Guid), bool returnImmediately = false, bool runAsynchronously = false, Guid storageClassificationID = default(Guid), bool systemVolume = false, VolumeTypeInfo volumeType = VolumeTypeInfo.None);
    VirtualDiskDriveInfo NewVirtualDiskDriveFromHostDiskToJobGroup(string scvmmServerName, int port, byte bus, VHDBusTypeInfo busType, byte lun, Guid jobGroup, Guid storageDiskID, bool bootVolume = false, string jobVariable = null, Guid proTipID = default(Guid), bool returnImmediately = false, bool runAsynchronously = false, Guid storageClassificationID = default(Guid), bool systemVolume = false, VolumeTypeInfo volumeType = VolumeTypeInfo.None);
    VirtualDiskDriveInfo NewVirtualDiskDriveFromHostDiskToVM(string scvmmServerName, int port, byte bus, VHDBusTypeInfo busType, byte lun, Guid storageDiskID, Guid vmID, bool bootVolume = false, string jobVariable = null, Guid proTipID = default(Guid), bool returnImmediately = false, bool runAsynchronously = false, Guid storageClassificationID = default(Guid), bool systemVolume = false, VolumeTypeInfo volumeType = VolumeTypeInfo.None);
    VirtualDiskDriveInfo NewVirtualDiskDriveFromNewToJobGroup(string scvmmServerName, int port, byte bus, VHDBusTypeInfo busType, byte lun, string fileName, Guid jobGroup, long virtualHardDiskSizeMB, bool isFixed = false, bool bootVolume = false, string jobVariable = null, Guid proTipID = default(Guid), bool returnImmediately = false, bool runAsynchronously = false, Guid storageClassificationID = default(Guid), bool systemVolume = false, VolumeTypeInfo volumeType = VolumeTypeInfo.None);
    VirtualDiskDriveInfo NewVirtualDiskDriveFromNewToTemplate(string scvmmServerName, int port, byte bus, VHDBusTypeInfo busType, byte lun, string fileName, long virtualHardDiskSizeMB, Guid vmTemplateID, bool isFixed = false, bool bootVolume = false, string jobVariable = null, Guid proTipID = default(Guid), bool returnImmediately = false, bool runAsynchronously = false, Guid storageClassificationID = default(Guid), bool systemVolume = false, VolumeTypeInfo volumeType = VolumeTypeInfo.None);
    VirtualDiskDriveInfo NewVirtualDiskDriveFromNewToVM(string scvmmServerName, int port, byte bus, VHDBusTypeInfo busType, byte lun, string fileName, long virtualHardDiskSizeMB, Guid vmID, bool isFixed = false, bool bootVolume = false, string jobVariable = null, Guid proTipID = default(Guid), bool returnImmediately = false, bool runAsynchronously = false, Guid storageClassificationID = default(Guid), bool systemVolume = false, VolumeTypeInfo volumeType = VolumeTypeInfo.None);

    //many more methods goes here...

    VMInfo NewStoredVirtualMachineFromHardwareProfile(string scvmmServerName, int port, string name, Guid libraryServerID, string sharePath = null, byte? cpuCount = null, bool? cpuLimitForMigration = null, bool? cpuLimitFuntionality = null, ushort? cpuRelativeWeight = null, Guid cpuTypeID = default(Guid), ushort? delayStartSeconds = null, string description = null, ushort? dynamicMemoryBufferPercentage = null, bool? dynamicMemoryEnabled = null, ushort? dynamicMemoryMaximumMB = null, Guid hardwareProfileID = default(Guid), Guid jobGroup = default(Guid), string jobVariable = null, ushort? memoryMB = null, ushort? memoryWeight = null, ushort? monitorMaximumCount = null, string monitorMaximumResolution = null, Guid operatingSystemID = default(Guid), string owner = null, Guid proTipID = default(Guid), bool returnImmediately = false, bool runAsynchronously = false, bool skipInstallVirtualizationGuestServices = false, VMStartActionInfo? startAction = null, VMStopActionInfo? stopAction = null, bool useLocalVirtualHardDisk = false, Guid userRoleID = default(Guid), bool? virtualVideoAdapterEnabled = null);
    VMInfo NewStoredVirtualMachineFromVirtualDisk(string scvmmServerName, int port, string name, Guid libraryServerID, string sharePath = null, Guid virtualHardDiskID = default(Guid), byte? cpuCount = null, bool? cpuLimitForMigration = null, bool? cpuLimitFuntionality = null, ushort? cpuRelativeWeight = null, Guid cpuTypeID = default(Guid), ushort? delayStartSeconds = null, string description = null, ushort? dynamicMemoryBufferPercentage = null, bool? dynamicMemoryEnabled = null, ushort? dynamicMemoryMaximumMB = null, Guid hardwareProfileID = default(Guid), Guid jobGroup = default(Guid), string jobVariable = null, ushort? memoryMB = null, ushort? memoryWeight = null, ushort? monitorMaximumCount = null, string monitorMaximumResolution = null, Guid operatingSystemID = default(Guid), string owner = null, Guid proTipID = default(Guid), bool returnImmediately = false, bool runAsynchronously = false, bool skipInstallVirtualizationGuestServices = false, VMStartActionInfo? startAction = null, VMStopActionInfo? stopAction = null, bool useLocalVirtualHardDisk = false, Guid userRoleID = default(Guid), bool? virtualVideoAdapterEnabled = null);
    VMInfo NewStoredVirtualMachineFromVirtualMachine(string scvmmServerName, int port, string name, Guid libraryServerID, string sharePath = null, Guid vmID = default(Guid), byte? cpuCount = null, bool? cpuLimitForMigration = null, bool? cpuLimitFuntionality = null, ushort? cpuRelativeWeight = null, Guid cpuTypeID = default(Guid), ushort? delayStartSeconds = null, string description = null, ushort? dynamicMemoryBufferPercentage = null, bool? dynamicMemoryEnabled = null, ushort? dynamicMemoryMaximumMB = null, Guid hardwareProfileID = default(Guid), Guid jobGroup = default(Guid), string jobVariable = null, ushort? memoryMB = null, ushort? memoryWeight = null, ushort? monitorMaximumCount = null, string monitorMaximumResolution = null, Guid operatingSystemID = default(Guid), string owner = null, Guid proTipID = default(Guid), bool returnImmediately = false, bool runAsynchronously = false, bool skipInstallVirtualizationGuestServices = false, VMStartActionInfo? startAction = null, VMStopActionInfo? stopAction = null, bool useLocalVirtualHardDisk = false, Guid userRoleID = default(Guid), bool? virtualVideoAdapterEnabled = null);
    VMInfo NewVirtualMachineFromComputerTierScaleOut(string scvmmServerName, int port, string name, Guid computerTierID, string computerName = null, byte? cpuCount = null, bool? cpuLimitForMigration = null, bool? cpuLimitFuntionality = null, ushort? cpuRelativeWeight = null, Guid cpuTypeID = default(Guid), ushort? delayStartSeconds = null, string description = null, ushort? dynamicMemoryBufferPercentage = null, bool? dynamicMemoryEnabled = null, ushort? dynamicMemoryMaximumMB = null, Guid hardwareProfileID = default(Guid), Guid jobGroup = default(Guid), string jobVariable = null, ushort? memoryMB = null, ushort? memoryWeight = null, ushort? monitorMaximumCount = null, string monitorMaximumResolution = null, Guid operatingSystemID = default(Guid), string owner = null, Guid proTipID = default(Guid), bool returnImmediately = false, bool runAsynchronously = false, bool skipInstallVirtualizationGuestServices = false, VMStartActionInfo? startAction = null, VMStopActionInfo? stopAction = null, bool useLocalVirtualHardDisk = false, Guid userRoleID = default(Guid), bool? virtualVideoAdapterEnabled = null);
    VMInfo NewVirtualMachineFromHardwareProfile(string scvmmServerName, int port, string name, string path, Guid vmHostID, bool blockDynamicOptimization = false, byte? cpuCount = null, bool? cpuLimitForMigration = null, bool? cpuLimitFuntionality = null, ushort? cpuRelativeWeight = null, Guid cpuTypeID = default(Guid), ushort? delayStartSeconds = null, string description = null, ushort? dynamicMemoryBufferPercentage = null, bool? dynamicMemoryEnabled = null, ushort? dynamicMemoryMaximumMB = null, Guid hardwareProfileID = default(Guid), bool? highlyAvailable = null, Guid jobGroup = default(Guid), string jobVariable = null, ushort? memoryMB = null, ushort? memoryWeight = null, ushort? monitorMaximumCount = null, string monitorMaximumResolution = null, Guid operatingSystemID = default(Guid), string owner = null, Guid proTipID = default(Guid), bool returnImmediately = false, bool runAsynchronously = false, bool skipInstallVirtualizationGuestServices = false, VMStartActionInfo? startAction = null, bool startVM = false, VMStopActionInfo? stopAction = null, bool useLocalVirtualHardDisk = false, Guid userRoleID = default(Guid), bool? virtualVideoAdapterEnabled = null);
    VMInfo NewVirtualMachineFromTemplate(string scvmmServerName, int port, string name, string path, Guid vmHostID, Guid vmTemplateID, Guid answerFileID, bool blockDynamicOptimization = false, string computerName = null, byte? cpuCount = null, bool? cpuLimitForMigration = null, bool? cpuLimitFuntionality = null, ushort? cpuRelativeWeight = null, Guid cpuTypeID = default(Guid), ushort? delayStartSeconds = null, string description = null, string domain = null, /*Microsoft.SystemCenter.VirtualMachineManager.Cmdlets.VMMCredential*/object domainJoinCredential = null, ushort? dynamicMemoryBufferPercentage = null, bool? dynamicMemoryEnabled = null, ushort? dynamicMemoryMaximumMB = null, string fullName = null, /*Microsoft.SystemCenter.VirtualMachineManager.GuestOSProfile*/object guestOSProfile = null, string[] guiRunOnceCommands = null, Guid hardwareProfileID = default(Guid), bool? highlyAvailable = null, Guid jobGroup = default(Guid), string jobVariable = null, ushort? memoryMB = null, ushort? memoryWeight = null, bool? mergeAnswerFile = null, ushort? monitorMaximumCount = null, string monitorMaximumResolution = null, Guid operatingSystemID = default(Guid), string organizationName = null, string owner = null, string productKey = null, Guid proTipID = default(Guid), bool returnImmediately = false, bool runAsynchronously = false, bool skipInstallVirtualizationGuestServices = false, VMStartActionInfo? startAction = null, bool startVM = false, VMStopActionInfo? stopAction = null, int? timeZone = null, bool useLocalVirtualHardDisk = false, Guid userRoleID = default(Guid), bool? virtualVideoAdapterEnabled = null, string workgroup = null);
    VMInfo NewVirtualMachineFromVirtualDisk(string scvmmServerName, int port, string name, string path, Guid virtualHardDiskID, Guid vmHostID, bool? blockDynamicOptimization = null, byte? cpuCount = null, bool? cpuLimitForMigration = null, bool? cpuLimitFuntionality = null, ushort? cpuRelativeWeight = null, Guid cpuTypeID = default(Guid), ushort? delayStartSeconds = null, string description = null, ushort? dynamicMemoryBufferPercentage = null, bool? dynamicMemoryEnabled = null, ushort? dynamicMemoryMaximumMB = null, Guid hardwareProfileID = default(Guid), bool? highlyAvailable = null, Guid jobGroup = default(Guid), string jobVariable = null, ushort? memoryMB = null, ushort? memoryWeight = null, ushort? monitorMaximumCount = null, string monitorMaximumResolution = null, Guid operatingSystemID = default(Guid), string owner = null, Guid proTipID = default(Guid), bool returnImmediately = false, bool runAsynchronously = false, bool skipInstallVirtualizationGuestServices = false, VMStartActionInfo? startAction = null, bool startVM = false, VMStopActionInfo? stopAction = null, bool useLocalVirtualHardDisk = false, Guid userRoleID = default(Guid), bool? virtualVideoAdapterEnabled = null);
    VMInfo NewVirtualMachineFromVirtualMachine(string scvmmServerName, int port, string name, string path, Guid vmID, Guid vmHostID, byte? cpuCount = null, bool? cpuLimitForMigration = null, bool? cpuLimitFuntionality = null, ushort? cpuRelativeWeight = null, Guid cpuTypeID = default(Guid), ushort? delayStartSeconds = null, string description = null, ushort? dynamicMemoryBufferPercentage = null, bool? dynamicMemoryEnabled = null, ushort? dynamicMemoryMaximumMB = null, Guid hardwareProfileID = default(Guid), bool? highlyAvailable = null, Guid jobGroup = default(Guid), string jobVariable = null, ushort? memoryMB = null, ushort? memoryWeight = null, ushort? monitorMaximumCount = null, string monitorMaximumResolution = null, Guid operatingSystemID = default(Guid), string owner = null, Guid proTipID = default(Guid), bool returnImmediately = false, bool runAsynchronously = false, bool skipInstallVirtualizationGuestServices = false, VMStartActionInfo? startAction = null, bool startVM = false, VMStopActionInfo? stopAction = null, bool useLocalVirtualHardDisk = false, Guid userRoleID = default(Guid), bool? virtualVideoAdapterEnabled = null);
    VMInfo NewVirtualMachineFromVirtualMachineCloud(string scvmmServerName, int port, string name, Guid cloudID, Guid vmID, Guid capabilityProfile = default(Guid), byte? cpuCount = null, bool? cpuLimitForMigration = null, bool? cpuLimitFuntionality = null, ushort? cpuRelativeWeight = null, Guid cpuTypeID = default(Guid), ushort? delayStartSeconds = null, string description = null, ushort? dynamicMemoryBufferPercentage = null, bool? dynamicMemoryEnabled = null, ushort? dynamicMemoryMaximumMB = null, Guid hardwareProfileID = default(Guid), bool? highlyAvailable = null, Guid jobGroup = default(Guid), string jobVariable = null, ushort? memoryMB = null, ushort? memoryWeight = null, ushort? monitorMaximumCount = null, string monitorMaximumResolution = null, Guid operatingSystemID = default(Guid), string owner = null, Guid proTipID = default(Guid), bool returnImmediately = false, bool runAsynchronously = false, Guid selfServiceUserRole = default(Guid), bool skipInstallVirtualizationGuestServices = false, VMStartActionInfo? startAction = null, bool startVM = false, VMStopActionInfo? stopAction = null, bool storeToLibrary = false, int? timeZone = null, bool useLocalVirtualHardDisk = false, Guid userRoleID = default(Guid), bool? virtualVideoAdapterEnabled = null, string workgroup = null);
    VMInfo NewVirtualMachineFromVirtualMachineConfiguration(string scvmmServerName, int port, string name, Guid vmConfigurationID, Guid answerFileID, bool? blockDynamicOptimization = null, Guid capabilityProfileID = default(Guid), Guid cloudID = default(Guid), string computerName = null, byte? cpuCount = null, bool? cpuLimitForMigration = null, bool? cpuLimitFuntionality = null, ushort? cpuRelativeWeight = null, Guid cpuTypeID = default(Guid), ushort? delayStartSeconds = null, string description = null, string domain = null, /*Microsoft.SystemCenter.VirtualMachineManager.Cmdlets.VMMCredential*/object domainJoinCredential = null, ushort? dynamicMemoryBufferPercentage = null, bool? dynamicMemoryEnabled = null, ushort? dynamicMemoryMaximumMB = null, string fullName = null, /*Microsoft.SystemCenter.VirtualMachineManager.GuestOSProfile*/object guestOSProfile = null, string[] guiRunOnceCommands = null, Guid hardwareProfileID = default(Guid), Guid jobGroup = default(Guid), string jobVariable = null, /*Microsoft.SystemCenter.VirtualMachineManager.Cmdlets.VMMCredential*/object localAdministratorCredential = null, ushort? memoryMB = null, ushort? memoryWeight = null, bool? mergeAnswerFile = null, ushort? monitorMaximumCount = null, string monitorMaximumResolution = null, Guid operatingSystemID = default(Guid), string organizationName = null, string owner = null, string productKey = null, Guid proTipID = default(Guid), bool returnImmediately = false, bool runAsynchronously = false, Guid selfServiceRoleID = default(Guid), bool skipInstallVirtualizationGuestServices = false, VMStartActionInfo? startAction = null, bool startVM = false, VMStopActionInfo? stopAction = null, bool storeToLibrary = false, int? timeZone = null, bool useLocalVirtualHardDisk = false, Guid userRoleID = default(Guid), bool? virtualVideoAdapterEnabled = null, string workgroup = null);
    VMInfo NewVirtualMachineFromVirtualMachineConfigurationScaleOut(string scvmmServerName, int port, string name, Guid vmConfigurationScaleOutID, byte? cpuCount = null, bool? cpuLimitForMigration = null, bool? cpuLimitFuntionality = null, ushort? cpuRelativeWeight = null, Guid cpuTypeID = default(Guid), ushort? delayStartSeconds = null, string description = null, ushort? dynamicMemoryBufferPercentage = null, bool? dynamicMemoryEnabled = null, ushort? dynamicMemoryMaximumMB = null, Guid hardwareProfileID = default(Guid), bool? highlyAvailable = null, Guid jobGroup = default(Guid), string jobVariable = null, ushort? memoryMB = null, ushort? memoryWeight = null, ushort? monitorMaximumCount = null, string monitorMaximumResolution = null, Guid operatingSystemID = default(Guid), string owner = null, Guid proTipID = default(Guid), bool returnImmediately = false, bool runAsynchronously = false, bool skipInstallVirtualizationGuestServices = false, VMStartActionInfo? startAction = null, VMStopActionInfo? stopAction = null, bool useLocalVirtualHardDisk = false, Guid userRoleID = default(Guid), bool? virtualVideoAdapterEnabled = null);
}

我已经像这样使用了这些服务方法;

private void CreateNewVM(ManagementServiceClient service)
{
    using (VMInfoForm vmForm = new VMInfoForm(null))
    {
        DialogResult result = vmForm.ShowDialog(this);
        if (result != System.Windows.Forms.DialogResult.OK)
            return;

        Guid jg = Guid.NewGuid();
        VirtualHardDiskInfo vhdiX = service.GetVirtualHardDiskByName(tbIP.Text, int.Parse(tbPort.Text), "X.vhd");
        VirtualDiskDriveInfo vdd = service.NewVirtualDiskDriveFromNewToJobGroup(tbIP.Text, int.Parse(tbPort.Text), 0, VHDBusTypeInfo.IDE, 0, string.Format("{0}_{1}", vmForm.VMName, "disk"), jg, 40960, volumeType: VolumeTypeInfo.BootAndSystem);
        VMInfo vm = service.NewVirtualMachineFromVirtualDisk(tbIP.Text, int.Parse(tbPort.Text), vmForm.VMName, @"C:\ProgramData\Microsoft\Windows\Hyper-V", vhdiX.ID, host.ID, returnImmediately: false, startAction: VMStartActionInfo.NeverAutoTurnOnVM, stopAction: VMStopActionInfo.SaveVM, jobGroup: jg);
        RefreshVMs(service); // Refresh the listbox of vm's.
    }
}

这段代码成功创建了一个虚拟机;但是,它没有附加磁盘。在我看来,我错过了一些东西。根据New-SCVirtualDiskDrive cmdlet 的文档,它创建一个虚拟硬盘驱动器,并作为返回值返回创建的磁盘对象(VirtualDiskDrive 的一个实例)。即使它成功执行,它也不会返回任何值。

顺便说一句,我还尝试使用以下代码的 ps 脚本版本并且它有效:创建了一个带有空硬盘的新虚拟机。

所以 New-SCVirtualDiskDrive cmdlet 存在问题。如何解决这个问题呢?你能帮忙吗?

4

1 回答 1

0

从查看脚本选项使用库服务器中的现有 VHD 创建 VM 将是:

New-SCVirtualDiskDrive -VMMServer $FQDNName -IDE -Bus 0 -LUN 0 -JobGroup $virtualDiskguid -CreateDiffDisk $false -virtualHardDisk $virtualHardDisk -VolumeType BootAndSystem -Verbose

其中$JobGroup是一组步骤一起执行时生成的uniqueID。

于 2015-05-06T17:58:25.463 回答