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 server or session name')][Alias('Server')][String]$MoveSession, [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 = if ($MoveSession) { Get-MoveSession -Name $MoveSession } else { Get-MoveSession } #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 } |