Skip to content

Commit d3a14ba

Browse files
authored
Fix HyperV XML: System.Xml.XmlElement & The minimum amount (hashicorp#13691)
* Fix HyperV XML: System.Xml.XmlElement & The minimum amount
1 parent dc39347 commit d3a14ba

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

plugins/providers/hyperv/scripts/utils/VagrantVM/VagrantVM.psm1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -333,32 +333,32 @@ function New-VagrantVMXML {
333333

334334
# Apply original VM configuration to new VM instance
335335

336-
if($CPUCount -ne $null) {
336+
if($CPUCount -ne $null -and $CPUCount -gt 0) {
337337
$processors = $CPUCount
338338
} else {
339339
$processors = $VMConfig.configuration.settings.processors.count."#text"
340340
}
341341
$notes = (Select-Xml -XML $VMConfig -XPath "//notes").node."#text"
342-
$memory = (Select-Xml -XML $VMConfig -XPath "//memory").node.Bank
343-
if ($memory.dynamic_memory_enabled."#text" -eq "True") {
342+
$memoryNode = (Select-Xml -XML $VMConfig -XPath "//memory").node.bank
343+
if ($memoryNode.dynamic_memory_enabled."#text" -eq "True") {
344344
$dynamicmemory = $True
345345
}
346346
else {
347347
$dynamicmemory = $False
348348
}
349349

350350

351-
if($Memory -ne $null) {
351+
if($Memory -ne $null -and $Memory -gt 0) {
352352
$MemoryMaximumBytes = $Memory * 1MB
353353
$MemoryStartupBytes = $Memory * 1MB
354354
$MemoryMinimumBytes = $Memory * 1MB
355355
} else {
356-
$MemoryMaximumBytes = ($memory.limit."#text" -as [int]) * 1MB
357-
$MemoryStartupBytes = ($memory.size."#text" -as [int]) * 1MB
358-
$MemoryMinimumBytes = ($memory.reservation."#text" -as [int]) * 1MB
356+
$MemoryMaximumBytes = ($memoryNode.limit."#text" -as [int]) * 1MB
357+
$MemoryStartupBytes = ($memoryNode.size."#text" -as [int]) * 1MB
358+
$MemoryMinimumBytes = ($memoryNode.reservation."#text" -as [int]) * 1MB
359359
}
360360

361-
if($MaxMemory -ne $null) {
361+
if($MaxMemory -ne $null -and $MaxMemory -gt 0) {
362362
$dynamicmemory = $true
363363
$MemoryMaximumBytes = $MaxMemory * 1MB
364364
}

0 commit comments

Comments
 (0)