Ejemplo de script de PowerShell con la API REST de CloudLink

Summary: Este archivo es solo para fines educativos/informativos. Se puede utilizar como referencia cuando se escriben scripts de automatización de CloudLink con el lenguaje de scripts de PowerShell. Dell no asume ninguna responsabilidad por el hecho de que este archivo se ejecute como un script de PowerShell en el entorno del cliente de Dell. El script muestra una manera de enumerar las máquinas registradas con Cloudlink y sus unidades desde un script de PowerShell mediante llamadas a la API Rest de Cloudlink. El script no altera el estado de ningún sistema, solo muestra información. El acceso al nodo de CloudLink (indicado por la dirección IP) se otorga con las credenciales de un usuario de Cloudlink de tipo "cliente". ...

This article applies to This article does not apply to This article is not tied to any specific product. Not all product versions are identified in this article.

Symptoms

El script se puede utilizar para automatizar las operaciones de Cloudlink. En este ejemplo, el script enumera las máquinas registradas en Cloudlink Center.

 

Cause

El script puede ser útil para los clientes que tienen varios CloudLink Center o que desean administrar su Cloudlink Center mediante un script de PowerShell.

 

Resolution

# Copyright Dell © 2021, 2022
# Este archivo es solo para fines educativos/informativos.
# Se puede utilizar como referencia cuando se escriben scripts de automatización de CloudLink con el lenguaje de scripts de PowerShell.
# Dell no asume ninguna responsabilidad por el hecho de que este archivo se ejecute como un script de PowerShell en el entorno del cliente de Dell.

# El script muestra una manera de enumerar máquinas registradas con Cloudlink y sus unidades desde un script de PowerShell mediante llamadas a la API REST de Cloudlink.
# El script no altera el estado de ningún sistema, solo muestra información.
# El acceso al nodo de CloudLink (indicado por la dirección IP) se otorga con las credenciales de un usuario de Cloudlink de tipo "cliente".

# La siguiente parte es simular la validación del certificado, el certificado siempre es válido.

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
if (-not ([System.Management.Automation.PSTypeName]'ServerCertificateValidationCallback').Type)
{
$certCallback = @"
    using System;
    using System.Net;
    using System.Net.Security;
    using System.Security.Cryptography.X509Certificates;
    public class ServerCertificateValidationCallback
    {
        public static void Ignore()
        {
            if(ServicePointManager.ServerCertificateValidationCallback ==null)
            {
                ServicePointManager.ServerCertificateValidationCallback +=
                    delegate
                    (
                        Object obj,
                        X509Certificate certificate,
                        X509Chain chain,
                        SslPolicyErrors errors
                    )
                    {
                        return true;
                    };
            }
        }
    }
"@
    Add-Type $certCallback
 }
[ServerCertificateValidationCallback]::Ignore()


$server='<cloudlink node ip>'
$client_id='<client id>'
$client_secret='<client secret>'

if ($args[0] -ne $null)
{  $server=$args[0] }

if ($args[1] -ne $null)
{  $client_id=$args[1] }

if ($args[2] -ne $null)
{  $client_secret=$args[2] }



$serverport=$server+":443"

Write-Output  "parameters: server=$server, client_id=$client_id, client_secret=$client_secret"

$responsee=Invoke-RestMethod -Uri "https://$server/cloudlink/oauth/token?grant_type=client_credentials&client_id=$client_id&client_secret=$client_secret&scope=all" -Method Get -TimeoutSec 1800
Write-Output "The response received:"
Write-Output "$responsee"



if($responsee.access_token)
{
  $mytoken=$responsee.access_token

  $Type = "application/json"
  $resolveSessionHeader = @{'Authorization' = "Bearer $mytoken"}

# Consulta de la lista de máquinas

  $machine_list_query='https://$serverport/cloudlink/rest/securevm'
  $machine_list=Invoke-WebRequest -Method Get -Uri $machine_list_query -Headers $resolveSessionHeader -ContentType $Type

# Enumere las máquinas en la consola.

  Write-Host "Machine list:" -ForegroundColor Yellow
  $machine_list_txt = $machine_list | ConvertFrom-Json
  $machine_list_txt | FT

#For cada máquina, enumere las unidades.

  foreach ($machine in $machine_list_txt)
  {
    $drives_list = $($machine.resources)
    Write-Host "$($machine.name) $($machine.ip_address) ($($machine.os_name)) group $($machine.group)" -ForegroundColor Yellow
    $drives_list | FT
  }
}

 

Affected Products

CloudLink SecureVM, CloudLink
Article Properties
Article Number: 000202396
Article Type: Solution
Last Modified: 09 Jun 2026
Version:  7
Find answers to your questions from other Dell users
Support Services
Check if your device is covered by Support Services.