Public/New-MovePlan.ps1

Function New-MovePlan {
    <#
    .SYNOPSIS
        Creates a new migration plan
    .DESCRIPTION
        Information required to create a migration plan include:
 
        Source provider information
        Target provider information
        Network mappings
        Schedule settings
        Workload
 
    .NOTES
        Implements details in https://www.nutanix.dev/api_reference/apis/move.html#tag/Plan/operation/createPlan
    .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
    #>


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

        [Parameter(
            Mandatory = $false,
            HelpMessage = 'Move Plan to create'
        )][psobject]$MovePlan
    )

    ## 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 }
    }

    $uri = "https://$($MoveSessionConfig.MoveServer):$($MoveSessionConfig.MovePort)/move/v2/plans"

    try {
        $RestMethodSplat = @{
            Uri            = $uri
            TimeoutSec     = 100
            Method         = 'POST'
            WebSession     = $MoveSessionConfig.MoveWebSession
            ProgressAction = 'SilentlyContinue'
            Body           = $MovePlan | ConvertTo-Json -Depth 10 -Compress
            MaximumRetryCount = 10
            RetryIntervalSec = (Get-Random -Minimum 5 -Maximum 15)
        }
        $Result = Invoke-RestMethod @RestMethodSplat @MoveCertSettings

    } catch {
        throw $_
    }
    return $Result
}