使用 Cloudlink REST API 的 PowerShell 脚本示例
Résumé: 此文件仅用于教育/信息目的。 在使用 PowerShell 脚本语言编写 Cloudlink 自动化脚本时,可用作参考。 对于此文件在戴尔客户环境中作为 PowerShell 脚本执行,戴尔不承担任何责任。 该脚本展示了一种使用 Cloudlink RestAPI 调用从 PowerShell 脚本列出向 Cloudlink 注册的计算机及其驱动器的方法。 脚本不会更改任何系统的状态,只会显示信息。 使用 “client” 类型的 Cloudlink 用户的凭据授予对 Cloudlink 节点(由 IP 地址指示)的访问权限。 ...
Cet article concerne
Cet article ne concerne pas
Cet article n’est associé à aucun produit spécifique.
Toutes les versions du produit ne sont pas identifiées dans cet article.
Symptômes
该脚本可用于自动执行 CloudLink 操作。在此示例中,脚本列出了向 Cloudlink Center 注册的计算机。
Cause
该脚本对于拥有多个 Cloudlink Center 的客户或希望使用 PowerShell 脚本管理其 Cloudlink Center 的客户可能非常有用。
Résolution
# 版权所有 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
}
}
Produits concernés
CloudLink SecureVM, CloudLinkPropriétés de l’article
Numéro d’article: 000202396
Type d’article: Solution
Dernière modification: 09 Jun 2026
Version: 7
Trouvez des réponses à vos questions auprès d’autres utilisateurs Dell
Services de support
Vérifiez si votre appareil est couvert par les services de support.