Тут достаточно все просто. Думаю не нужно дополнительного описания
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# Script to clone a VM in Hyper-V $SourceVMName = "mini-templ" $CloneVMName = "new-vm-name" $ExportFolder = "F:\Hyper-V\Virtual Machine" $CloneFolder = "F:\Hyper-V\Virtual Machines\$CloneVMName" If (Test-Path $CloneFolder){ Write-Warning "Clone folder: $CloneFolder already exists. Aborting script..." Break } # Export the Source VM Export-VM $SourceVMName -Path $ExportFolder # Import the Exported VM, full copy, and generating a new ID $CloneVMConfigFile = (Get-ChildItem "$ExportFolder\$SourceVMName" -Filter *.vmcx -Recurse | Select -First 1).Fullname $CloneVMConfig = @{ Path = $CloneVMConfigFile; SnapshotFilePath = Join-Path $CloneFolder "Snapshots"; VhdDestinationPath = Join-Path $CloneFolder "Virtual Hard Disks"; VirtualMachinePath = $CloneFolder; } $Result = Import-VM -Copy -GenerateNewID @CloneVMConfig # Rename the imported VM (will be imported with original name) $Result | Rename-VM -NewName $CloneVMName # Remove the exported VM $SourceVMExportPath = "$ExportFolder\$SourceVMName" If (Test-Path $SourceVMExportPath) { Remove-Item -Path $SourceVMExportPath -Recurse -Force } #Start new VM Start-VM -Name $CloneVMName |