From 10181f7c8aef3066bcd1b34fc105535eee539dc8 Mon Sep 17 00:00:00 2001 From: Bjorn Brala Date: Wed, 23 Nov 2016 08:39:49 +0100 Subject: [PATCH] When you set the memory of a HyperV machine to something lower than the original range it fails. --- .../providers/hyperv/scripts/import_vm_vmcx.ps1 | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/plugins/providers/hyperv/scripts/import_vm_vmcx.ps1 b/plugins/providers/hyperv/scripts/import_vm_vmcx.ps1 index 9554fb91e..e4e13e913 100644 --- a/plugins/providers/hyperv/scripts/import_vm_vmcx.ps1 +++ b/plugins/providers/hyperv/scripts/import_vm_vmcx.ps1 @@ -36,7 +36,7 @@ $generation = $vmConfig.VM.Generation if (!$vmname) { # Get the name of the vm $vm_name = $vmconfig.VM.VMName -}else { +} else { $vm_name = $vmname } @@ -86,15 +86,18 @@ if (!$switchname) { $switchname = (Get-VMNetworkAdapter -VM $vmConfig.VM).SwitchName } -Connect-VMNetworkAdapter -VMNetworkAdapter (Get-VMNetworkAdapter -VM $vmConfig.VM) -SwitchName $switchname -Set-VM -VM $vmConfig.VM -NewVMName $vm_name -MemoryStartupBytes $MemoryStartupBytes -Set-VM -VM $vmConfig.VM -ErrorAction "Stop" -ProcessorCount $processors +$vmNetworkAdapter = Get-VMNetworkAdapter -VM $vmConfig.VM +Connect-VMNetworkAdapter -VMNetworkAdapter $vmNetworkAdapter -SwitchName $switchname +Set-VM -VM $vmConfig.VM -NewVMName $vm_name +Set-VM -VM $vmConfig.VM -ErrorAction "Stop" +Set-VM -VM $vmConfig.VM -ProcessorCount $processors -If ($dynamicmemory) { +if ($dynamicmemory) { Set-VM -VM $vmConfig.VM -DynamicMemory - Set-VM -VM $vmConfig.VM -MemoryMinimumBytes $MemoryMinimumBytes -MemoryMaximumBytes $MemoryMaximumBytes + Set-VM -VM $vmConfig.VM -MemoryMinimumBytes $MemoryMinimumBytes -MemoryMaximumBytes $MemoryMaximumBytes -MemoryStartupBytes $MemoryStartupBytes } else { - Set-VM -VM $vmConfig.VM -StaticMemory + Set-VM -VM $vmConfig.VM -StaticMemory + Set-VM -VM $vmConfig.VM -MemoryStartupBytes $MemoryStartupBytes } if ($notes) {