使用 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 = @“
,使用系统;
  使用 System.Net;
  使用 System.Net.Security;
  使用 System.Security.Cryptography.X509 认证;
  公共类 ServerCertificateValidationCallback
{
公共静态无效 忽略()
{
if(ServicePointManager.ServerCertificateValidationCallback ==null)
{
ServicePointManager.ServerCertificateValidationCallback +=
delegate

Object obj,
X509Certificate 证书,
                      X509Chain 链,
SslPolicyErrors 错误

{
返回 true;
                  };
          } }

}
“@
Add-Type $certCallback
}
[ServerCertificateValidationCallback]:::ignore()


$server=''
$client_id=''$client
_secret=''if ($args'

$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”
写入输出 “参数: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 grant_type=$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

# 列出控制台
上的计算机
写入主机“计算机列表:”   -前台Color黄色
$machine_list_txt = $machine_list |ConvertFrom-Json
$machine_list_txt |FT

#For每台计算机, 列出驱动器
前缀($machine在 $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, CloudLink
Propriétés de l’article
Numéro d’article: 000202396
Type d’article: Solution
Dernière modification: 13 mars 2023
Version:  5
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.