使用 Cloudlink REST API 的 PowerShell 脚本示例
摘要: 此文件仅用于教育/信息目的。 在使用 PowerShell 脚本语言编写 Cloudlink 自动化脚本时,可用作参考。 对于此文件在戴尔客户环境中作为 PowerShell 脚本执行,戴尔不承担任何责任。 该脚本展示了一种使用 Cloudlink RestAPI 调用从 PowerShell 脚本列出向 Cloudlink 注册的计算机及其驱动器的方法。 脚本不会更改任何系统的状态,只会显示信息。 使用 “client” 类型的 Cloudlink 用户的凭据授予对 Cloudlink 节点(由 IP 地址指示)的访问权限。 ...
本文适用于
本文不适用于
本文并非针对某种特定的产品。
本文并非包含所有产品版本。
症状
该脚本可用于自动执行 CloudLink 操作。在此示例中,脚本列出了向 Cloudlink Center 注册的计算机。
原因
该脚本对于拥有多个 Cloudlink Center 的客户或希望使用 PowerShell 脚本管理其 Cloudlink Center 的客户可能非常有用。
解决方案
# 版权所有 Dell © 2021、2022
# 此文件仅用于教育/信息目的。
#在使用 PowerShell 脚本语言编写 Cloudlink 自动化脚本时,可用作参考。
#对于此文件在戴尔客户环境中作为 PowerShell 脚本执行,戴尔不承担任何责任。
# 该脚本展示了一种使用 Cloudlink RestAPI 调用从 PowerShell 脚本列出向 Cloudlink 注册的计算机及其驱动器的方法。
#脚本不会更改任何系统的状态,只会显示信息。
#使用 “client” 类型的 Cloudlink 用户的凭据授予对 Cloudlink 节点(由 IP 地址指示)的访问权限。
# 以下部分是模拟证书验证,证书始终有效。
[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
}
}
受影响的产品
CloudLink SecureVM, CloudLink文章属性
文章编号: 000202396
文章类型: Solution
上次修改时间: 09 6月 2026
版本: 7
从其他戴尔用户那里查找问题的答案
支持服务
检查您的设备是否在支持服务涵盖的范围内。