public/Stop-VM.ps1

function Stop-ZStackVM {
    # .SYNOPSIS
    # Requests a graceful VM shutdown.
    # .DESCRIPTION
    # ZStack PowerCLI (ZStack.PowerCLI 1.1.5) uses CLI 1.1.5, commit 6fcf509ff540d0098f54c1c33609dbe9f572c837.
    # Connection configuration namespace: zstack-powershell.
    # .LINK
    # https://github.com/terraform-zstack-modules/zstack-cli-go/blob/main/docs/powershell.md
    [CmdletBinding(DefaultParameterSetName = 'VM', SupportsShouldProcess, ConfirmImpact = 'Medium')]
    param(
        [Parameter(Mandatory, Position = 0, ValueFromPipeline, ParameterSetName = 'VM')] [ValidateNotNullOrEmpty()] [object[]] $VM,
        [Parameter(Mandatory, ParameterSetName = 'Id')] [ValidateNotNullOrEmpty()] [ValidatePattern('\A[A-Za-z0-9-]{1,128}\z')] [string[]] $Id,
        [switch] $StopHA,
        [ValidateRange(1, 3600)] [int] $TimeoutSeconds = 300,
        [ValidateRange(1, 60)] [int] $PollSeconds = 2,
        [object] $Server
    )
    process {
        $parameter = $PSCmdlet.ParameterSetName
        $options = @()
        if ($PSBoundParameters.ContainsKey('StopHA')) { $options += "--stop-ha=$($StopHA.IsPresent.ToString().ToLowerInvariant())" }
        Invoke-CloudVMLifecycle -Caller $PSCmdlet -ParameterSet $parameter -Selectors $PSBoundParameters[$parameter] -Server $Server -Command stop -Operation StopVM -Description 'Gracefully stop VM' -State Stopped -TimeoutSeconds $TimeoutSeconds -PollSeconds $PollSeconds -Options $options
    }
}