Public/Get-MultiHypervisorVm.ps1

<#
    .DESCRIPTION
    Wrapper for Nutanix API version 0.3.
 
    .NOTES
    Author: Timothy Rasiah
#>


function Get-MultiHypervisorVm {
    [CmdletBinding()]
    param (
        $uuid,
        $name,
        [Switch]$All
    )

    if ($uuid) {
        $response = Send-Request -method "GET" -endpoint "/mh_vms/$($uuid)"
        return $response
    }

    $data = @{
        "kind" = "mh_vm"
    }

    if ($name) {
        $data["filter"] = "vm_name==$($name)"
    }

    $entities = @()
    $length = 20
    $offset = 0
    do {
        $data["length"] = $length
        $data["offset"] = $offset

        $response = Send-Request -method "POST" -endpoint "/mh_vms/list" -data $data
        $entities += $response.entities

        $offset += $length
        $length = 500
    } while ($All -and $offset -lt $response.metadata.total_matches)
    return $entities
}