使用 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
質問に対する他のDellユーザーからの回答を見つける
サポート サービス
お使いのデバイスがサポート サービスの対象かどうかを確認してください。