I have a Hyper-V lab I run on my laptop (Windows 8.1, dual quad processor, 32G RAM, 2 HDs) that has 7-9 virtual machines (VMs) running.  When I’m done working on my lab I typically SAVE all the running VMs instead of shutting them down.  The next time I need to run the lab I start all the saved VMs.  This is much quicker than waiting for all the operating systems to boot. 

Windows 8 will do this for me automatically but I since I’m a control freak I like to control these actions myself.  One important note.  These are LAB MACHINES.  You should never perform a SAVE action on a production VM especially Active Directory domain controllers.

In the past I would open the Hyper-V console, select all the SAVED systems and click “start” and then reverse the process to shut down the lab.  It occurred to last week I could control these actions faster and easier with PowerShell.  I created two functions named START-LAB and STOP-LAB and added them to my PowerShell profile so they are available in every PowerShell session.  Now I just open an elevated PowerShell window and type the name of the appropriate function.  The code for the functions is shown below:

#START-LAB
Function Start-Lab {
if ((get-vm).count -eq 0)
    {Write-host
     Write-host -foregroundcolor RED "        Cannot Start VMs"    
     Write-host -foregroundcolor RED "        PowerShell is not Running with Elevated Credentials"
     Write-Host
     Exit}
  Else
    {Write-Host
         Write-host "        Starting all SAVED VMs...."
         Write-Host
    get-vm |where {$_.state -eq "saved"} | Start-VM
    }
} #END Start-Lab

#STOP-LAB
Function Stop-Lab {
if ((get-vm).count -eq 0)
    {Write-host
      Write-host -foregroundcolor RED "        Cannot Stop VMs"    
     Write-host -foregroundcolor RED "        PowerShell is not Running with Elevated Credentials"
     Write-Host
     Exit}
  Else
    {Write-Host
         Write-host "        Saving all running VMs...."
         Write-Host
    get-vm |where {$_.state -eq "running"} | Save-VM
    }
} #END Stop-Lab