|
|
|
|
@ -366,10 +366,10 @@ Hyper-V\Set-VMNetworkAdapter $vmName -staticmacaddress $mac
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ImportVmcxVirtualMachine(importPath string, vmName string, harddrivePath string,
|
|
|
|
|
ram int64, switchName string) error {
|
|
|
|
|
ram int64, switchName string, copyTF bool) error {
|
|
|
|
|
|
|
|
|
|
var script = `
|
|
|
|
|
param([string]$importPath, [string]$vmName, [string]$harddrivePath, [long]$memoryStartupBytes, [string]$switchName)
|
|
|
|
|
param([string]$importPath, [string]$vmName, [string]$harddrivePath, [long]$memoryStartupBytes, [string]$switchName, [string]$copy)
|
|
|
|
|
|
|
|
|
|
$VirtualHarddisksPath = Join-Path -Path $importPath -ChildPath 'Virtual Hard Disks'
|
|
|
|
|
if (!(Test-Path $VirtualHarddisksPath)) {
|
|
|
|
|
@ -395,7 +395,13 @@ if (!$VirtualMachinePath){
|
|
|
|
|
$VirtualMachinePath = Get-ChildItem -Path $importPath -Filter *.xml -Recurse -ErrorAction SilentlyContinue | select -First 1 | %{$_.FullName}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$compatibilityReport = Hyper-V\Compare-VM -Path $VirtualMachinePath -VirtualMachinePath $importPath -SmartPagingFilePath $importPath -SnapshotFilePath $importPath -VhdDestinationPath $VirtualHarddisksPath -GenerateNewId
|
|
|
|
|
$copyBool = $false
|
|
|
|
|
switch($copy) {
|
|
|
|
|
"true" { $copyBool = $true }
|
|
|
|
|
default { $copyBool = $false }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$compatibilityReport = Hyper-V\Compare-VM -Path $VirtualMachinePath -VirtualMachinePath $importPath -SmartPagingFilePath $importPath -SnapshotFilePath $importPath -VhdDestinationPath $VirtualHarddisksPath -GenerateNewId -Copy:$false
|
|
|
|
|
if ($vhdPath){
|
|
|
|
|
Copy-Item -Path $harddrivePath -Destination $vhdPath
|
|
|
|
|
$existingFirstHarddrive = $compatibilityReport.VM.HardDrives | Select -First 1
|
|
|
|
|
@ -415,16 +421,15 @@ if ($vm) {
|
|
|
|
|
$result = Hyper-V\Rename-VM -VM $vm -NewName $VMName
|
|
|
|
|
}
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
var ps powershell.PowerShellCmd
|
|
|
|
|
err := ps.Run(script, importPath, vmName, harddrivePath, strconv.FormatInt(ram, 10), switchName)
|
|
|
|
|
err := ps.Run(script, importPath, vmName, harddrivePath, strconv.FormatInt(ram, 10), switchName, strconv.FormatBool(copyTF))
|
|
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func CloneVirtualMachine(cloneFromVmcxPath string, cloneFromVmName string,
|
|
|
|
|
cloneFromSnapshotName string, cloneAllSnapshots bool, vmName string,
|
|
|
|
|
path string, harddrivePath string, ram int64, switchName string) error {
|
|
|
|
|
path string, harddrivePath string, ram int64, switchName string, copyTF bool) error {
|
|
|
|
|
|
|
|
|
|
if cloneFromVmName != "" {
|
|
|
|
|
if err := ExportVmcxVirtualMachine(path, cloneFromVmName,
|
|
|
|
|
@ -439,7 +444,7 @@ func CloneVirtualMachine(cloneFromVmcxPath string, cloneFromVmName string,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := ImportVmcxVirtualMachine(path, vmName, harddrivePath, ram, switchName); err != nil {
|
|
|
|
|
if err := ImportVmcxVirtualMachine(path, vmName, harddrivePath, ram, switchName, copyTF); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|