Exemplo de script do PowerShell usando a API REST do CloudLink

Summary: Este arquivo é apenas para fins educacionais/informativos. Pode ser usado como referência ao escrever scripts de automação do CloudLink com a linguagem de script do PowerShell. A Dell não assume nenhuma responsabilidade por esse arquivo ser executado como um script do PowerShell no ambiente do Cliente Dell. O script mostra uma maneira de listar as máquinas registradas no Cloudlink e suas unidades a partir de um script do PowerShell usando chamadas RestAPI do Cloudlink. O script não altera o estado de nenhum sistema, apenas exibe informações. O acesso ao nó do Cloudlink (indicado pelo endereço IP) é concedido com as credenciais de um usuário do Cloudlink do tipo 'client'. ...

Αυτό το άρθρο ισχύει για Αυτό το άρθρο δεν ισχύει για Αυτό το άρθρο δεν συνδέεται με κάποιο συγκεκριμένο προϊόν. Δεν προσδιορίζονται όλες οι εκδόσεις προϊόντων σε αυτό το άρθρο.

Symptoms

O script pode ser usado para automatizar as operações do CloudLink. Neste exemplo, o script lista as máquinas registradas no Cloudlink Center.

 

Cause

O script pode ser útil para clientes que têm vários Cloudlink Centers ou que desejam gerenciar o Cloudlink Center usando um script do PowerShell.

 

Resolution

# Copyright Dell © 2021, 2022
# Este arquivo é apenas para fins educacionais/informativos.
# Pode ser usado como referência ao escrever scripts de automação do CloudLink com a linguagem de script do PowerShell.
# A Dell não assume nenhuma responsabilidade por esse arquivo ser executado como um script do PowerShell no ambiente do Cliente Dell.

# O script mostra uma maneira de listar as máquinas registradas com o Cloudlink e suas unidades a partir de um script do PowerShell usando chamadas RestAPI do Cloudlink.
# O script não altera o estado de nenhum sistema, apenas exibe informações.
# O acesso ao nó do Cloudlink (indicado pelo endereço IP) é concedido com as credenciais de um usuário do Cloudlink do tipo 'client'.

# A parte a seguir é zombar da validação do certificado, o certificado é sempre 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 para a 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

# Listar as máquinas no console.

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

#For cada máquina, liste as 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
  }
}

 

Επηρεαζόμενα προϊόντα

CloudLink SecureVM, CloudLink
Ιδιότητες άρθρου
Article Number: 000202396
Article Type: Solution
Τελευταία τροποποίηση: 09 Ιουν 2026
Version:  7
Βρείτε απαντήσεις στις ερωτήσεις σας από άλλους χρήστες της Dell
Υπηρεσίες υποστήριξης
Ελέγξτε αν η συσκευή σας καλύπτεται από τις Υπηρεσίες υποστήριξης.