使用 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
向其他 Dell 使用者尋求您問題的答案
支援服務
檢查您的裝置是否在支援服務的涵蓋範圍內。