From 4642b0effa0c4171e212af57457768eb4282796a Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Peters Date: Mon, 17 Sep 2018 19:32:18 +0200 Subject: [PATCH] Streamlined Save-LabVm function --- AutomatedLab/AutomatedLabVirtualMachines.psm1 | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/AutomatedLab/AutomatedLabVirtualMachines.psm1 b/AutomatedLab/AutomatedLabVirtualMachines.psm1 index f547961bd..d0643a3d3 100644 --- a/AutomatedLab/AutomatedLabVirtualMachines.psm1 +++ b/AutomatedLab/AutomatedLabVirtualMachines.psm1 @@ -401,25 +401,15 @@ function Save-LabVM Write-ScreenInfo 'There is no machine to start' -Type Warning return } - - foreach ($vm in $vms) + + Write-Verbose -Message "Saving VMs '$($vms -join ',')" + switch ($lab.DefaultVirtualizationEngine) { - Write-Verbose "Saving VMs '$vm'" - - if ($vm.HostType -eq 'HyperV') - { - Save-LWHypervVM -ComputerName $vm - } - elseif ($vm.HostType -eq 'Azure') - { - Write-Error 'Azure does not support saving machines' - } - elseif ($vm.HostType -eq 'VMWare') - { - Save-LWVMWareVM -ComputerName $vm - } + 'HyperV' { Save-LWHypervVM -ComputerName $vms} + 'VMWare' { Save-LWVMWareVM -ComputerName $vms} + 'Azure' { Write-Warning -Message "Skipping Azure VMs '$($vms -join ',')' as suspending the VMs is not supported on Azure."} } - + Write-LogFunctionExit } }