functions/Invoke-ShutdownLab.ps1

Function Invoke-ShutdownLab {
    [CmdletBinding(SupportsShouldProcess)]
    [alias("Shutdown-Lab")]
    Param (
        [Parameter(HelpMessage = "The path to the configuration folder. Normally, you should run all commands from within the configuration folder.")]
        [ValidateNotNullOrEmpty()]
        [ValidateScript( { Test-Path $_ })]
        [String]$Path = ".",
        [Parameter(HelpMessage = "Run the command but suppress all status messages.")]
        [Alias("Quiet")]
        [Switch]$NoMessages
    )

    $Path = Convert-Path $path

    if (-Not $NoMessages) {

        Microsoft.PowerShell.Utility\Write-Host -ForegroundColor Green -Object @"
 
        This is the Shutdown-Lab command. It will perform the following:
 
        * Shutdown the Lab environment:
 
"@

    }

    $LabName = Split-Path $path -Leaf
    if (-Not $NoMessages) {
        Microsoft.PowerShell.Utility\Write-Host -ForegroundColor Cyan -Object 'Stopping the lab environment'
    }
    # Creates the lab environment without making a Hyper-V Snapshot
    if ($PSCmdlet.ShouldProcess($LabName, "Stop-Lab")) {
        Try {
            Stop-Lab -ConfigurationData $path\*.psd1 -ErrorAction Stop
        }
        Catch {
            Write-Warning "Failed to stop lab. Are you running this in the correct configuration directory? $($_.exception.message)"
            #bail out because no other commands are likely to work
            return
        }
    }

    if (-Not $NoMessages) {

        Microsoft.PowerShell.Utility\Write-Host -ForegroundColor Green -Object @"
 
        Next Steps:
 
        When the configurations have finished, you can checkpoint the VM's with:
        Snapshot-Lab
 
        To quickly rebuild the labs from the checkpoint, run:
        Refresh-Lab
 
        To start the lab environment:
        Run-Lab
 
        To destroy the lab environment:
        Wipe-Lab
 
"@

    }
}