Public/Invoke-MovePlanAction.ps1
|
Function Invoke-MovePlanAction { <# .SYNOPSIS Triggers a Move Plan action. .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 = 'Move Plan ID')][String]$PlanId, [Parameter(Mandatory = $false, HelpMessage = 'Workload ID')][String]$WorkloadId, [ValidateSet('cutover', 'test', 'undotest')] [Parameter(Mandatory = $true, HelpMessage = 'Move Plan Action')][String]$Action ) ## 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/workloads/action' -f $MoveSessionConfig.MoveServer, $MoveSessionConfig.MovePort TimeoutSec = 100 Method = 'POST' WebSession = $MoveSessionConfig.MoveWebSession ProgressAction = 'SilentlyContinue' Body = @{ Spec = @{ Action = $Action.ToLower() WorkloadReferences = @( @{ PlanReference = $PlanId WorkloadReference = $WorkloadId } ) } } | ConvertTo-Json -Depth 3 -Compress } try { $Result = Invoke-RestMethod @RestMethodSplat @MoveCertSettings } catch { throw $_.Exception.Message } if ($Result.Status.ErrorMessage) { throw $Result.Status.ErrorMessage } return $Result } |