Public/Get-MovePlan.ps1
|
function Get-MovePlan { <# .SYNOPSIS List details of all migration plans, or get a single plan .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(DefaultParameterSetName = 'ByID')] param( [Parameter(Mandatory = $false, HelpMessage = 'Move Session Name')][string]$MoveSession = 'Default', [Parameter(Mandatory = $false, ParameterSetName = 'ByID', HelpMessage = 'Provider ID')][string]$Id, [Parameter(ParameterSetName = 'ListAvailable')][switch]$ListAvailable, [Parameter()][switch]$ListWorkloads ) $MoveSessionConfig = Get-MoveSession $MoveSession $RestMethodSplat = @{ Uri = 'https://{0}:{1}/move/v2/plans' -f $MoveSessionConfig.MoveServer, $MoveSessionConfig.MovePort TimeoutSec = 100 Method = 'GET' WebSession = $MoveSessionConfig.MoveWebSession ProgressAction = 'SilentlyContinue' SkipCertificateCheck = $MoveSessionConfig.AllowInsecureSSL } switch ($PSCmdlet.ParameterSetName) { 'ByID' { $RestMethodSplat.Uri += "/$($Id)" $RestMethodSplat.Method = 'GET' } 'ListAvailable' { $RestMethodSplat.Uri += '/list' $RestMethodSplat.Method = 'POST' $RestMethodSplat.Body = @{EntityType = 'VM' } | ConvertTo-Json -Compress } } ## Always get all the VM Details $RestMethodSplat.Uri += '?IncludeVMDetails=true' try { $Result = Invoke-RestMethod @RestMethodSplat } 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 Add-Member -InputObject $Entity -NotePropertyName 'Workloads' -NotePropertyValue $Workloads } } return $Result } |