2013-02-14 46 views
1

我已經下載DDCTK-H SCVMM 2012 Samples並修改了WCF項目一點點使用SCVMM的全部功能2012使用SCVMM PowerShell命令:新SCVirtualDiskDrive使用

我的目的是從現有的VHD創建虛擬機。現在我可以創建一個虛擬機,但是我無法用硬盤創建虛擬機。現在我放棄嘗試使用現有的vhd來完成它,並且想用空的IDE硬盤創建一個vm。

我試着在SCVMM 2012的虛擬管理器控制檯上用現有的獨立vhd創建虛擬機。這裏有一個嚮導,最後通過點擊「查看腳本」,你可以看到這項工作所需的所有腳本。

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. 
    } 
} 

該代碼成功創建了一個vm;但是,沒有磁盤連接到它。在我看來,我錯過了一些東西。根據New-SCVirtualDiskDrive cmdlet的文檔,它會創建一個虛擬硬盤驅動器,並作爲返回值返回創建的磁盤對象(VirtualDiskDrive的一個實例)。即使它成功執行,它也不會返回任何值。

順便說一句,我也試過使用ps腳本版本的下面的代碼,它的工作原理:一個新的VM與空硬盤創建。

因此,New-SCVirtualDiskDrive cmdlet存在問題。如何解決這個問題呢?你能幫忙嗎?

回答

0

從視圖腳本選項使用現有的VHD從庫服務器將是創建VM:

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

當一組的步驟被執行在一起,其中$JobGroup被UNIQUEID生成。