Advertisement
bagaudin

reddit.1j2s2em

Mar 3rd, 2025
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Define your Acronis API credentials and endpoint
  2. $baseUrl = "https://uk01-cloud.acronis.com"
  3.  
  4. #---CUSTOMER LEVEL API CLIENT---
  5. $clientId = "111111"
  6. $clientSecret = "1111111"
  7.  
  8. # Function to get an access token using client credentials
  9. function Get-AccessToken {
  10.     try {
  11.         $body = @{
  12.             "grant_type"    = "client_credentials"
  13.             "client_id"     = $clientId
  14.             "client_secret" = $clientSecret
  15.         }
  16.         $response = Invoke-RestMethod -Uri "$baseUrl/api/2/idp/token" -Method Post -Body $body -ContentType "application/x-www-form-urlencoded"
  17.  
  18.         if ($response.access_token) {
  19.             Write-Host "Successfully obtained access token."
  20.             return $response.access_token
  21.         } else {
  22.             Write-Host "Failed to obtain access token."
  23.             return $null
  24.         }
  25.     } catch {
  26.         Write-Host "Error fetching access token: $_"
  27.         return $null
  28.     }
  29. }
  30.  
  31. # Get the access token
  32. $accessToken = Get-AccessToken
  33.  
  34. if (-not $accessToken) {
  35.     Write-Host "Access token retrieval failed. Exiting..."
  36.     exit
  37. }
  38.  
  39. # Function to get the backup status of a device
  40. function Get-BackupStatus {
  41.     $headers = @{
  42.         "Authorization" = "Bearer $accessToken"
  43.     }
  44.  
  45.     try {
  46.         $response = Invoke-RestMethod -Uri "$baseUrl/bc/api/task_manager/v2/tasks" -Headers $headers -Method Get
  47.         $response | ConvertTo-Json -Depth 100
  48.         return $response
  49.     } catch {
  50.         Write-Host "Error fetching backup status: $_"
  51.         return $null
  52.     }
  53. }
  54.  
  55. # Get the backup status
  56. $backupStatus = Get-BackupStatus
  57.  
  58. # Output the backup status
  59. if ($backupStatus) {
  60.    
  61.     $backupStatus | Format-List
  62.  
  63. } else {
  64.     Write-Host "Failed to retrieve backup status."
  65. }
Tags: Reddit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement