Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Define your Acronis API credentials and endpoint
- $baseUrl = "https://uk01-cloud.acronis.com"
- #---CUSTOMER LEVEL API CLIENT---
- $clientId = "111111"
- $clientSecret = "1111111"
- # Function to get an access token using client credentials
- function Get-AccessToken {
- try {
- $body = @{
- "grant_type" = "client_credentials"
- "client_id" = $clientId
- "client_secret" = $clientSecret
- }
- $response = Invoke-RestMethod -Uri "$baseUrl/api/2/idp/token" -Method Post -Body $body -ContentType "application/x-www-form-urlencoded"
- if ($response.access_token) {
- Write-Host "Successfully obtained access token."
- return $response.access_token
- } else {
- Write-Host "Failed to obtain access token."
- return $null
- }
- } catch {
- Write-Host "Error fetching access token: $_"
- return $null
- }
- }
- # Get the access token
- $accessToken = Get-AccessToken
- if (-not $accessToken) {
- Write-Host "Access token retrieval failed. Exiting..."
- exit
- }
- # Function to get the backup status of a device
- function Get-BackupStatus {
- $headers = @{
- "Authorization" = "Bearer $accessToken"
- }
- try {
- $response = Invoke-RestMethod -Uri "$baseUrl/bc/api/task_manager/v2/tasks" -Headers $headers -Method Get
- $response | ConvertTo-Json -Depth 100
- return $response
- } catch {
- Write-Host "Error fetching backup status: $_"
- return $null
- }
- }
- # Get the backup status
- $backupStatus = Get-BackupStatus
- # Output the backup status
- if ($backupStatus) {
- $backupStatus | Format-List
- } else {
- Write-Host "Failed to retrieve backup status."
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement