From 3ffaf551c08b69dd0e00715bbb37199e4e6482b4 Mon Sep 17 00:00:00 2001 From: Hannu Piki Date: Thu, 29 Mar 2018 18:31:19 +0300 Subject: [PATCH] Fixing Hyper-V ISO builder CopyExportedVirtualMachine PowerShell Script wasn't able to handle path that Packer used to create VM in the first place: "==> hyperv-iso: Copying to output dir... ==> hyperv-iso: Error exporting vm: PowerShell error: Move-Item : An object at the specified path C:\Users\HANNU~1.PIK does not exist. ==> hyperv-iso: At C:\Users\hannu.piki\AppData\Local\Temp\ps520830935.ps1:13 char:1 ==> hyperv-iso: + Move-Item -Path "$srcPath/$vhdDirName" -Destination $dstPath -Verbose ==> hyperv-iso: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ==> hyperv-iso: + CategoryInfo : InvalidArgument: (:) [Move-Item], PSArgumentException ==> hyperv-iso: + FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.MoveItemCommand" Used path was: C:\Users\HANNU~1.PIK\AppData\Local\Temp\packerhv616791918\export253729206\2016min Real path was: C:\Users\hannu.piki\AppData\Local\Temp\packerhv616791918\export253729206\2016min --- common/powershell/hyperv/hyperv.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/powershell/hyperv/hyperv.go b/common/powershell/hyperv/hyperv.go index d5b58f5db..f1dfc940c 100644 --- a/common/powershell/hyperv/hyperv.go +++ b/common/powershell/hyperv/hyperv.go @@ -649,9 +649,9 @@ func CopyExportedVirtualMachine(expPath string, outputPath string, vhdDir string var script = ` param([string]$srcPath, [string]$dstPath, [string]$vhdDirName, [string]$vmDir) -Move-Item -Path $srcPath/*.* -Destination $dstPath -Move-Item -Path $srcPath/$vhdDirName -Destination $dstPath -Move-Item -Path $srcPath/$vmDir -Destination $dstPath +Move-Item -Path (Join-Path (Get-Item $srcPath).FullName "*.*") -Destination $dstPath +Move-Item -Path (Join-Path (Get-Item $srcPath).FullName $vhdDirName) -Destination $dstPath +Move-Item -Path (Join-Path (Get-Item $srcPath).FullName $vmDir) -Destination $dstPath ` var ps powershell.PowerShellCmd