Public/Stop-VirtualMachine.ps1

<#
.SYNOPSIS
    Stops the user preferred virtual machine.
.DESCRIPTION
    This function uses the Stop-VM cmdlet to stop the virtual machine specified by the user.
    The user must have previously registered the virtual machine aliases using the Register-VirtualMachineAliases function.
.EXAMPLE
    # Register the virtual machine aliases for the WDK VM
    Register-VirtualMachineAliases -Name "Windows 11 WDK Environment" -Credential (Import-Clixml "${env:USERPROFILE}\.cert\wdkcert.xml")
     
    # Stop the WDK VM
    Stop-VirtualMachine
#>

function Stop-VirtualMachine {
    if (-not $script:VirtualMachineManager) {
        throw "Virtual Machine aliases are not registered. Run Register-VirtualMachineAliases first."
    }

    Stop-VM -Name $script:VirtualMachineManager.VMName
}