vagrant/plugins/providers/hyperv/scripts/import_vm.ps1
Chris Roberts 6a0f875833
Fix hyperv import failure due to lack of resources
When importing a box that was built with more resources than is
available on the current system, import would fail. If the memory
and/or cpu values are set in the Vagrantfile configuration, provide
them when importing the guest. This allows the values to be modified
prior to registering the new guest preventing a resource unavailability
error.

Fixes #12180
2025-05-20 18:10:49 -07:00

47 lines
1.2 KiB
PowerShell

# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: BUSL-1.1
#Requires -Modules VagrantVM, VagrantMessages
param(
[parameter (Mandatory=$true)]
[string] $VMConfigFile,
[parameter (Mandatory=$true)]
[string] $DestinationPath,
[parameter (Mandatory=$true)]
[string] $DataPath,
[parameter (Mandatory=$true)]
[string] $SourcePath,
[parameter (Mandatory=$false)]
[switch] $LinkedClone,
[parameter (Mandatory=$false)]
[int] $Memory = $null,
[parameter (Mandatory=$false)]
[int] $MaxMemory = $null,
[parameter (Mandatory=$false)]
[int] $Processors = $null,
[parameter (Mandatory=$false)]
[string] $VMName=$null
)
$ErrorActionPreference = "Stop"
try {
if($LinkedClone) {
$linked = $true
} else {
$linked = $false
}
$VM = New-VagrantVM -VMConfigFile $VMConfigFile -DestinationPath $DestinationPath `
-DataPath $DataPath -SourcePath $SourcePath -LinkedClone $linked -Memory $Memory `
-MaxMemory $MaxMemory -CPUCount $Processors -VMName $VMName
$Result = @{
id = $VM.Id.Guid;
}
Write-OutputMessage (ConvertTo-Json $Result)
} catch {
Write-ErrorMessage "${PSItem}"
exit 1
}