Public/Start-MovePlan.ps1

Function Start-MovePlan {
    <#
    .SYNOPSIS
        Starts a Move Plan's replication
    .DESCRIPTION
 
    .NOTES
        Implements details in https://www.nutanix.dev/api_reference/apis/move.html#tag/Plan/operation/getPlan
    .LINK
        Specify a URI to a help page, this will show when Get-Help -Online is used.
    .EXAMPLE
        Get-MoveExampleSomething -Verbose
        Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines
    #>


    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $false,
            HelpMessage = 'Move Session Name')][String]$MoveSession = 'Default',
        [Parameter(Mandatory = $false,
            HelpMessage = 'Provider ID')][String]$Id

    )

    ## Get Session Configuration
    $MoveSessionConfig = $global:MoveSessions[$MoveSession]
    if (-not $MoveSessionConfig) {
        Write-Host 'MoveSession: [' -NoNewline
        Write-Host $MoveSession -ForegroundColor Cyan
        Write-Host '] was not Found. Please use the New-MoveSession command.'
        Throw 'Move Session Not Found. Use New-MoveSession command before using features.'
    }

    #Honor SSL Settings
    if ($MoveSessionConfig.AllowInsecureSSL) {
        $MoveCertSettings = @{SkipCertificateCheck = $true }
    } else {
        $MoveCertSettings = @{SkipCertificateCheck = $false }
    }
    $RestMethodSplat = @{
        Uri            = 'https://{0}:{1}/move/v2/plans/{2}/start' -f $MoveSessionConfig.MoveServer, $MoveSessionConfig.MovePort, $Id
        TimeoutSec     = 100
        Method         = 'POST'
        WebSession     = $MoveSessionConfig.MoveWebSession
        ProgressAction = 'SilentlyContinue'
    }

    try {
        $Result = Invoke-RestMethod @RestMethodSplat @MoveCertSettings

    } catch {
        throw $_.Exception.Message
    }

    if ($ListWorkloads.IsPresent) {

        $RestMethodSplat.Method = 'POST'
        foreach ($Entity in $Result.Entities) {

            $RestMethodSplat.Uri = 'https://{0}:{1}/move/v2/plans/{2}/workloads/list' -f $MoveSessionConfig.MoveServer, $MoveSessionConfig.MovePort, $Entity.MetaData.UUID
            $RestMethodSplat.Body = $Null
            $Workloads = Invoke-RestMethod @RestMethodSplat @MoveCertSettings
            Add-Member -InputObject $Entity -NotePropertyName 'Workloads' -NotePropertyValue $Workloads
        }
    }

    return $Result
}