Esempio di script PowerShell utilizzando l'API REST CloudLink
Zusammenfassung: Questo file è solo a scopo formativo/informativo. Può essere utilizzato come riferimento quando si scrivono script di automazione CloudLink con il linguaggio di script PowerShell. Dell declina ogni responsabilità per l'esecuzione di questo file come script PowerShell nell'ambiente del Cliente Lo script mostra un modo per elencare i computer registrati con CloudLink e le relative unità da uno script PowerShell utilizzando le chiamate CloudLink RestAPI. Lo script non altera lo stato di alcun sistema, ma visualizza solo le informazioni. L'accesso al nodo CloudLink (indicato dall'indirizzo IP) viene concesso con le credenziali di un utente Cloudlink di tipo "client". ...
Dieser Artikel gilt für
Dieser Artikel gilt nicht für
Dieser Artikel ist nicht an ein bestimmtes Produkt gebunden.
In diesem Artikel werden nicht alle Produktversionen aufgeführt.
Symptome
Lo script può essere utilizzato per automatizzare le operazioni cloudlink. In questo esempio lo script elenca i computer registrati con Cloudlink Center.
Ursache
Lo script potrebbe essere utile per i clienti che dispongono di diversi centri CloudLink o che desiderano gestire il proprio CloudLink Center utilizzando uno script PowerShell.
Lösung
# Copyright Dell © 2021, 2022
# Questo file è solo a scopo formativo/informativo.
# Può essere utilizzato come riferimento quando si scrivono script di automazione CloudLink con il linguaggio di script PowerShell.
# Dell non si assume alcuna responsabilità per l'esecuzione di questo file come script PowerShell nell'ambiente
del Cliente Dell# Lo script mostra un modo per elencare i computer registrati con CloudLink e le relative unità da uno script
PowerShell # utilizzando le chiamate RestAPI di CloudLink.
# Lo script non altera lo stato di alcun sistema, ma visualizza solo le informazioni.
# L'accesso al nodo CloudLink (indicato dall'indirizzo IP) viene concesso con le credenziali di un utente Cloudlink di tipo "client".
# La parte seguente si basa sulla convalida del certificato, il certificato è sempre valido
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
se (-not (-not ([System.Management.Automation.PSTypeName]'ServerCertificateValidationCallback'). Tipo)
{
$certCallback = @"
utilizzando il sistema;
utilizzando System.Net;
utilizzando System.Net.Security;
utilizzo di System.Security.Cryptography.X509Certificates;
public class ServerCertificateValidationCallback
{
public static void Ignore()
{
if(ServicePointManager.ServerCertificateValidationCallback =null)
{
ServicePointManager.ServerCertificateValidationCallback +=
delegate
(
object obj,
certificato X509Certificate,
X509Chain chain,
Errori SslPolicyErrors
)
{
restituiscono true;
};
}
}
}
"@
Add-Type $certCallback
}
[ServerCertificateValidationCallback]::Ignore()
$server=''
$client_id=''
$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"}
# Query per l'elenco
computer $machine_list_query='https://$serverport/cloudlink/rest/securevm'
$machine_list=Invoke-WebRequest -Method Get -Uri $machine_list_query -Headers $resolveSessionHeader -ContentType $Type
# Elencare i computer sulla console
Write-Host "Machine list:" -Primo pianoColore giallo
$machine_list_txt = $machine_list | ConvertFrom-Json
$machine_list_txt | FT
#For ogni computer, elencare le unità
anteriori ($machine in $machine_list_txt)
{
$drives_list = $($machine.resources)
Write-Host "$($machine.name) $($machine.ip_address) ($($machine.os_name)) group $($machine.group)" -In primo pianoColor yellow
$drives_list | FT
}
}
# Questo file è solo a scopo formativo/informativo.
# Può essere utilizzato come riferimento quando si scrivono script di automazione CloudLink con il linguaggio di script PowerShell.
# Dell non si assume alcuna responsabilità per l'esecuzione di questo file come script PowerShell nell'ambiente
del Cliente Dell# Lo script mostra un modo per elencare i computer registrati con CloudLink e le relative unità da uno script
PowerShell # utilizzando le chiamate RestAPI di CloudLink.
# Lo script non altera lo stato di alcun sistema, ma visualizza solo le informazioni.
# L'accesso al nodo CloudLink (indicato dall'indirizzo IP) viene concesso con le credenziali di un utente Cloudlink di tipo "client".
# La parte seguente si basa sulla convalida del certificato, il certificato è sempre valido
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
se (-not (-not ([System.Management.Automation.PSTypeName]'ServerCertificateValidationCallback'). Tipo)
{
$certCallback = @"
utilizzando il sistema;
utilizzando System.Net;
utilizzando System.Net.Security;
utilizzo di System.Security.Cryptography.X509Certificates;
public class ServerCertificateValidationCallback
{
public static void Ignore()
{
if(ServicePointManager.ServerCertificateValidationCallback =null)
{
ServicePointManager.ServerCertificateValidationCallback +=
delegate
(
object obj,
certificato X509Certificate,
X509Chain chain,
Errori SslPolicyErrors
)
{
restituiscono true;
};
}
}
}
"@
Add-Type $certCallback
}
[ServerCertificateValidationCallback]::Ignore()
$server=''
$client_id=''
$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"}
# Query per l'elenco
computer $machine_list_query='https://$serverport/cloudlink/rest/securevm'
$machine_list=Invoke-WebRequest -Method Get -Uri $machine_list_query -Headers $resolveSessionHeader -ContentType $Type
# Elencare i computer sulla console
Write-Host "Machine list:" -Primo pianoColore giallo
$machine_list_txt = $machine_list | ConvertFrom-Json
$machine_list_txt | FT
#For ogni computer, elencare le unità
anteriori ($machine in $machine_list_txt)
{
$drives_list = $($machine.resources)
Write-Host "$($machine.name) $($machine.ip_address) ($($machine.os_name)) group $($machine.group)" -In primo pianoColor yellow
$drives_list | FT
}
}
Betroffene Produkte
CloudLink SecureVM, CloudLinkArtikeleigenschaften
Artikelnummer: 000202396
Artikeltyp: Solution
Zuletzt geändert: 15 Mai 2026
Version: 6
Antworten auf Ihre Fragen erhalten Sie von anderen Dell NutzerInnen
Support Services
Prüfen Sie, ob Ihr Gerät durch Support Services abgedeckt ist.