From 961624998b17bab7b31a96a9d998f801e3ded5b0 Mon Sep 17 00:00:00 2001 From: djpbessems Date: Sat, 13 Feb 2021 20:16:31 +0100 Subject: [PATCH] Fix path;Add conditional --- packer/windowsserver2019.json | 6 +++--- scripts/Remove-Resources.ps1 | 22 ++++++++++++++-------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/packer/windowsserver2019.json b/packer/windowsserver2019.json index c2f3cf2..0dbc03d 100644 --- a/packer/windowsserver2019.json +++ b/packer/windowsserver2019.json @@ -218,12 +218,12 @@ "type": "shell-local", "inline": [ "pwsh -command \"& scripts/Update-OvfConfiguration.ps1 \\", - " -OVFFile '/scratch/output-srv2019-v/{{user `vm_guestos`}}-{{user `vm_name`}}.ovf' \\", + " -OVFFile '/scratch/srv2019-v/{{user `vm_guestos`}}-{{user `vm_name`}}.ovf' \\", " -Parameter @{'appliance.name'='{{user `vm_guestos`}}';'appliance.version'='{{user `vm_name`}}'}\"", "pwsh -file scripts/Update-Manifest.ps1 \\", - " -ManifestFileName '/scratch/output-srv2019-v/{{user `vm_guestos`}}-{{user `vm_name`}}.mf'", + " -ManifestFileName '/scratch/srv2019-v/{{user `vm_guestos`}}-{{user `vm_name`}}.mf'", "ovftool --acceptAllEulas --allowExtraConfig --overwrite \\", - " '/scratch/output-srv2019-v/{{user `vm_guestos`}}-{{user `vm_name`}}.ovf' \\", + " '/scratch/srv2019-v/{{user `vm_guestos`}}-{{user `vm_name`}}.ovf' \\", " /output/Windows-Server-2019-LTSC.ova" ] } diff --git a/scripts/Remove-Resources.ps1 b/scripts/Remove-Resources.ps1 index 31c964d..e2c247a 100644 --- a/scripts/Remove-Resources.ps1 +++ b/scripts/Remove-Resources.ps1 @@ -26,14 +26,20 @@ $ConnectVIServerSplat = @{ } Connect-VIServer @ConnectVIServerSplat | Out-Null -$RemoveVMSplat = @{ - VM = "$($VMName)*" - DeletePermanently = $True - Confirm = $False - ErrorAction = 'SilentlyContinue' +$GetVMSplat = @{ + VM = "$($VMName)*" + ErrorAction = 'SilentlyContinue' +} +If ([boolean](Get-VM @GetVMSplat)) { + $RemoveVMSplat = @{ + VM = "$($VMName)*" + DeletePermanently = $True + Confirm = $False + ErrorAction = 'SilentlyContinue' + } + Remove-VM @RemoveVMSplat } -Remove-VM @RemoveVMSplat -# Also delete ISO/floppy? +Disconnect-VIServer * -Confirm:$False -Disconnect-VIServer * -Confirm:$False \ No newline at end of file +# Delete scratch folder contents