使用 Cloudlink REST 應用程式發展介面的 PowerShell 腳本範例
摘要: 此檔案僅用於教育/資訊用途。 使用 PowerShell 指令碼語言寫入 Cloudlink 自動化腳本時,可作為參考。 在 Dell 客戶的環境中,以 PowerShell 指令檔執行此檔案時,Dell 概不負責 此指令檔會顯示使用 Cloudlink RestAPI 呼叫,列出以 Cloudlink 註冊的機器及其 PowerShell 指令檔中的磁片磁碟機的方式。 此腳本不會變更任何系統的狀態,只需顯示資訊即可。 使用類型「用戶端」的 Cloudlink 使用者認證授予 Cloudlink 節點 (IP 位址所指示) 的存取權。 ...
本文适用于
本文不适用于
本文并非针对某种特定的产品。
本文并非包含所有产品版本。
症状
此腳本可用於自動化 Cloudlink 作業。在此範例中,指令檔會列出向 Cloudlink Center 註冊的機器。
原因
對於擁有數個 Cloudlink Center 或想要使用 PowerShell 腳本管理其 Cloudlink Center 的客戶,此腳本可能會有所説明。
解决方案
# 版權所有 Dell © 2021,2022
# 此檔案僅用於教育/資訊用途。
#使用 PowerShell 指令碼語言寫入 Cloudlink 自動化腳本時,可作為參考。
#在 Dell 客戶的環境中
,Dell 將以 PowerShell 指令檔方式執行此檔案,Dell 概不負責。 此指令檔會顯示一種方式,列出使用 Cloudlink 註冊的機器,以及使用 Cloudlink RestAPI 呼叫從 PowerShell 腳本
編號中執行的磁片磁碟機。
#此腳本不會變更任何系統的狀態,只需顯示資訊即可。
#使用類型「用戶端」的 Cloudlink 使用者認證授予 Cloudlink 節點 (IP 位址所指示) 的存取權。
#下列零件是在類比憑證驗證,憑證一律有效
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
if (-not ([System.Management.Automation.PSTypeName]'ServerCertationValidationCallback')。Type)
{
$certCallback = @「
(使用系統;
使用 System.Net;
使用 System.Net.Security;
使用 System.Security.Cryptography.X509Certates;
公家級 ServerCertateValidationCallback
{
公用靜態作廢忽略 ()
{
if(ServicePointManager.ServerCertationValidationCallback ==null)
{
ServicePointManager.ServerCertateValidationCallback +=
delegate
(
Object obj、
X509Certate 憑證、
X509 鏈結、
SslPolicyErrors 錯誤
)
{
返回 true;
};
} }
}
「@
Add-Type $certCallback
}
[ServerCertationValidationCallback]::Ignore()
$server=''
$client_id=''$client_secret=''if ($args client id>'
'
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」
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_credentials=$client_id&client_secret=$client_secret&scope=all「 -Method Get -TimeoutSec 1800
Write-Output 」收到的回應:「
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: -前臺Color 黃色
$machine_list_txt = $machine_list |ConvertFrom-Json
$machine_list_txt |FT
#For每台機器, 列出 forach 磁片磁碟機
($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
} }
# 此檔案僅用於教育/資訊用途。
#使用 PowerShell 指令碼語言寫入 Cloudlink 自動化腳本時,可作為參考。
#在 Dell 客戶的環境中
,Dell 將以 PowerShell 指令檔方式執行此檔案,Dell 概不負責。 此指令檔會顯示一種方式,列出使用 Cloudlink 註冊的機器,以及使用 Cloudlink RestAPI 呼叫從 PowerShell 腳本
編號中執行的磁片磁碟機。
#此腳本不會變更任何系統的狀態,只需顯示資訊即可。
#使用類型「用戶端」的 Cloudlink 使用者認證授予 Cloudlink 節點 (IP 位址所指示) 的存取權。
#下列零件是在類比憑證驗證,憑證一律有效
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
if (-not ([System.Management.Automation.PSTypeName]'ServerCertationValidationCallback')。Type)
{
$certCallback = @「
(使用系統;
使用 System.Net;
使用 System.Net.Security;
使用 System.Security.Cryptography.X509Certates;
公家級 ServerCertateValidationCallback
{
公用靜態作廢忽略 ()
{
if(ServicePointManager.ServerCertationValidationCallback ==null)
{
ServicePointManager.ServerCertateValidationCallback +=
delegate
(
Object obj、
X509Certate 憑證、
X509 鏈結、
SslPolicyErrors 錯誤
)
{
返回 true;
};
} }
}
「@
Add-Type $certCallback
}
[ServerCertationValidationCallback]::Ignore()
$server=''
$client_id=''$client_secret=''if ($args client id>'
'
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」
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_credentials=$client_id&client_secret=$client_secret&scope=all「 -Method Get -TimeoutSec 1800
Write-Output 」收到的回應:「
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: -前臺Color 黃色
$machine_list_txt = $machine_list |ConvertFrom-Json
$machine_list_txt |FT
#For每台機器, 列出 forach 磁片磁碟機
($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
} }
受影响的产品
CloudLink SecureVM, CloudLink文章属性
文章编号: 000202396
文章类型: Solution
上次修改时间: 13 3月 2023
版本: 5
从其他戴尔用户那里查找问题的答案
支持服务
检查您的设备是否在支持服务涵盖的范围内。