From 8bf25b5f552df3b9545baf652f7f918070b71ab8 Mon Sep 17 00:00:00 2001 From: djpbessems Date: Sat, 13 Feb 2021 22:07:01 +0100 Subject: [PATCH] Fix VM name;Fix cmdlet param;Purge scratch folder --- packer/windowsserver2019.json | 6 +++--- scripts/Remove-Resources.ps1 | 12 +++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packer/windowsserver2019.json b/packer/windowsserver2019.json index 0dbc03d..2ba4fa0 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/srv2019-v/{{user `vm_guestos`}}-{{user `vm_name`}}.ovf' \\", + " -OVFFile '/scratch/srv2019-v/{{user `vm_guestos`}}-{{user `vm_name`}}-v.ovf' \\", " -Parameter @{'appliance.name'='{{user `vm_guestos`}}';'appliance.version'='{{user `vm_name`}}'}\"", "pwsh -file scripts/Update-Manifest.ps1 \\", - " -ManifestFileName '/scratch/srv2019-v/{{user `vm_guestos`}}-{{user `vm_name`}}.mf'", + " -ManifestFileName '/scratch/srv2019-v/{{user `vm_guestos`}}-{{user `vm_name`}}-v.mf'", "ovftool --acceptAllEulas --allowExtraConfig --overwrite \\", - " '/scratch/srv2019-v/{{user `vm_guestos`}}-{{user `vm_name`}}.ovf' \\", + " '/scratch/srv2019-v/{{user `vm_guestos`}}-{{user `vm_name`}}-v.ovf' \\", " /output/Windows-Server-2019-LTSC.ova" ] } diff --git a/scripts/Remove-Resources.ps1 b/scripts/Remove-Resources.ps1 index e2c247a..19b9705 100644 --- a/scripts/Remove-Resources.ps1 +++ b/scripts/Remove-Resources.ps1 @@ -27,12 +27,12 @@ $ConnectVIServerSplat = @{ Connect-VIServer @ConnectVIServerSplat | Out-Null $GetVMSplat = @{ - VM = "$($VMName)*" + Name = "$($VMName)*" ErrorAction = 'SilentlyContinue' } If ([boolean](Get-VM @GetVMSplat)) { $RemoveVMSplat = @{ - VM = "$($VMName)*" + VM = Get-VM @GetVMSplat DeletePermanently = $True Confirm = $False ErrorAction = 'SilentlyContinue' @@ -42,4 +42,10 @@ If ([boolean](Get-VM @GetVMSplat)) { Disconnect-VIServer * -Confirm:$False -# Delete scratch folder contents +$RemoveItemSplat = @{ + Path = '/scratch/*' + Recurse = $True + Force = $True + Confirm = $False +} +Remote-Item @RemoveItemSplat \ No newline at end of file