From d93b37b60aad169ec9c99eea240147bf0f7641af Mon Sep 17 00:00:00 2001 From: chazragg Date: Sun, 26 Nov 2023 00:13:52 +0000 Subject: [PATCH 1/3] Added Alternative condition for "Virtual Hard Disks" check --- api/hyperv-winrm/vhd.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/api/hyperv-winrm/vhd.go b/api/hyperv-winrm/vhd.go index 14caeff1..e6596d30 100644 --- a/api/hyperv-winrm/vhd.go +++ b/api/hyperv-winrm/vhd.go @@ -81,6 +81,7 @@ function Expand-Downloads { ) process { Push-Location $FolderPath + $vhdPath = Get-ChildItem $tempPath *"Virtual Hard Disks"* -Recurse -Directory get-item *.zip | % { $tempPath = join-path $FolderPath "temp" @@ -97,8 +98,8 @@ function Expand-Downloads { [System.IO.Compression.ZipFile]::ExtractToDirectory($_.FullName, $tempPath) } - if (Test-Path "$tempPath\Virtual Hard Disks") { - Move-Item "$tempPath\Virtual Hard Disks\*.*" $FolderPath + if (Test-Path $($vhdPath.FullName)) { + Move-Item $($vhdPath.FullName)\*.* $FolderPath } else { Move-Item "$tempPath\*.*" $FolderPath } @@ -116,8 +117,8 @@ function Expand-Downloads { $command = """$7zPath"" x ""$($_.FullName)"" -o""$tempPath""" & cmd.exe /C $command - if (Test-Path "$tempPath\Virtual Hard Disks") { - Move-Item "$tempPath\Virtual Hard Disks\*.*" $FolderPath + if (Test-Path $($vhdPath.FullName)) { + Move-Item $"($vhdPath.FullName)\*.*" $FolderPath } else { Move-Item "$tempPath\*.*" $FolderPath } @@ -139,8 +140,8 @@ function Expand-Downloads { $command = """$tarPath"" -C ""$tempPath"" -x -f ""$($_.FullName)""" & cmd.exe /C $command - if (Test-Path "$tempPath\Virtual Hard Disks") { - Move-Item "$tempPath\Virtual Hard Disks\*.*" $FolderPath + if (Test-Path $($vhdPath.FullName)) { + Move-Item "$($vhdPath.FullName)\*.*" $FolderPath } else { Move-Item "$tempPath\*.*" $FolderPath } From 924b36f00ca81dd1030684e539a9481e11411c42 Mon Sep 17 00:00:00 2001 From: chazragg Date: Sun, 26 Nov 2023 00:16:37 +0000 Subject: [PATCH 2/3] Fixed formatting --- api/hyperv-winrm/vhd.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/api/hyperv-winrm/vhd.go b/api/hyperv-winrm/vhd.go index e6596d30..907bc0b6 100644 --- a/api/hyperv-winrm/vhd.go +++ b/api/hyperv-winrm/vhd.go @@ -99,7 +99,7 @@ function Expand-Downloads { } if (Test-Path $($vhdPath.FullName)) { - Move-Item $($vhdPath.FullName)\*.* $FolderPath + Move-Item "$($vhdPath.FullName)\*.*" $FolderPath } else { Move-Item "$tempPath\*.*" $FolderPath } @@ -117,8 +117,8 @@ function Expand-Downloads { $command = """$7zPath"" x ""$($_.FullName)"" -o""$tempPath""" & cmd.exe /C $command - if (Test-Path $($vhdPath.FullName)) { - Move-Item $"($vhdPath.FullName)\*.*" $FolderPath + if (Test-Path $($vhdPath.FullName)) { + Move-Item "$($vhdPath.FullName)\*.*" $FolderPath } else { Move-Item "$tempPath\*.*" $FolderPath } @@ -140,7 +140,7 @@ function Expand-Downloads { $command = """$tarPath"" -C ""$tempPath"" -x -f ""$($_.FullName)""" & cmd.exe /C $command - if (Test-Path $($vhdPath.FullName)) { + if (Test-Path $($vhdPath.FullName)) { Move-Item "$($vhdPath.FullName)\*.*" $FolderPath } else { Move-Item "$tempPath\*.*" $FolderPath From 1a94deb4371cf85d37551bc35e119f185ecbcc23 Mon Sep 17 00:00:00 2001 From: Taliesin Sisson Date: Sun, 14 Jan 2024 21:02:54 +0000 Subject: [PATCH 3/3] Need to get children folder in the loop --- api/hyperv-winrm/vhd.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/api/hyperv-winrm/vhd.go b/api/hyperv-winrm/vhd.go index 907bc0b6..75a2a6b6 100644 --- a/api/hyperv-winrm/vhd.go +++ b/api/hyperv-winrm/vhd.go @@ -81,7 +81,6 @@ function Expand-Downloads { ) process { Push-Location $FolderPath - $vhdPath = Get-ChildItem $tempPath *"Virtual Hard Disks"* -Recurse -Directory get-item *.zip | % { $tempPath = join-path $FolderPath "temp" @@ -98,6 +97,8 @@ function Expand-Downloads { [System.IO.Compression.ZipFile]::ExtractToDirectory($_.FullName, $tempPath) } + $vhdPath = Get-ChildItem $tempPath *"Virtual Hard Disks"* -Recurse -Directory + if (Test-Path $($vhdPath.FullName)) { Move-Item "$($vhdPath.FullName)\*.*" $FolderPath } else { @@ -117,7 +118,9 @@ function Expand-Downloads { $command = """$7zPath"" x ""$($_.FullName)"" -o""$tempPath""" & cmd.exe /C $command - if (Test-Path $($vhdPath.FullName)) { + $vhdPath = Get-ChildItem $tempPath *"Virtual Hard Disks"* -Recurse -Directory + + if ($vhdPath -and Test-Path $($vhdPath.FullName)) { Move-Item "$($vhdPath.FullName)\*.*" $FolderPath } else { Move-Item "$tempPath\*.*" $FolderPath @@ -140,7 +143,9 @@ function Expand-Downloads { $command = """$tarPath"" -C ""$tempPath"" -x -f ""$($_.FullName)""" & cmd.exe /C $command - if (Test-Path $($vhdPath.FullName)) { + $vhdPath = Get-ChildItem $tempPath *"Virtual Hard Disks"* -Recurse -Directory + + if ($vhdPath -and Test-Path $($vhdPath.FullName)) { Move-Item "$($vhdPath.FullName)\*.*" $FolderPath } else { Move-Item "$tempPath\*.*" $FolderPath