使用 Cloudlink REST API 的 PowerShell 指令檔範例

Summary: 此檔僅用於教育/資訊目的。 在使用 PowerShell 指令碼語言寫入 Cloudlink 自動化指令檔時,可作為參考。 對於此檔案在 Dell 客戶的環境中以 PowerShell 指令檔執行,Dell 概不負責。 此指令檔顯示如何使用 Cloudlink RestAPI 呼叫,列出透過 PowerShell 指令檔向 Cloudlink 註冊的機器及其磁碟機的方法。 此指令檔不會變更任何系統的狀態,只會顯示資訊。 Cloudlink 節點 (由 IP 位址指示) 的存取權是以類型為「用戶端」的 Cloudlink 使用者的登入資料授予。 ...

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

此指令檔可用於自動化 Cloudlink 作業。在此範例中,指令檔會列出已向 Cloudlink Center 註冊的電腦。

 

Cause

對於擁有多個 Cloudlink 中心或想要使用 PowerShell 指令檔管理其 Cloudlink Center 的客戶,此指令檔可能十分實用。

 

Resolution

# 著作權所有 Dell © 2021、2022
# 此檔案僅供教育/參考之用。
#在使用 PowerShell 指令碼語言寫入 Cloudlink 自動化指令檔時,可作為參考。
#對於此檔案在 Dell 客戶的環境中以 PowerShell 指令檔執行,Dell 概不負責。

# 此指令檔顯示如何使用 Cloudlink RestAPI 呼叫,列出透過 PowerShell 指令檔向 Cloudlink 註冊的機器及其磁碟機。
#此指令檔不會變更任何系統的狀態,只會顯示資訊。
#Cloudlink 節點 (由 IP 位址指示) 的存取權是以類型為「用戶端」的 Cloudlink 使用者的登入資料授予。

# 以下部分是模擬憑證驗證,證書始終有效。

[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"}

# 查詢機器清單

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

# 列出控制臺上的機器。

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

#For 每台機器上,列出驅動器。

  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.