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 server or session name')][Alias('Server')][String]$MoveSession, [Parameter(Mandatory = $false, HelpMessage = 'Provider ID')][String]$Id ) ## 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/{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 } |