Advertisement
Ubidibity

20231204 Veeam backup files

Dec 4th, 2023
1,547
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 1.75 KB | Source Code | 0 0
  1. # Replace these variables with your actual credentials and server details
  2. $veeamServer = "your_veeam_server"
  3. $username = "your_username"
  4. $password = "your_password"
  5.  
  6. # Function to authenticate and get the token
  7. function Get-VeeamAuthToken {
  8.     $authBody = @{
  9.         grant_type = "password"
  10.         username   = $username
  11.         password   = $password
  12.     }
  13.  
  14.     $authResponse = Invoke-RestMethod -Method Post -Uri "http://$veeamServer:9419/api/oauth2/token" -Body $authBody
  15.     return $authResponse.access_token
  16. }
  17.  
  18. # Function to get backup repository information
  19. function Get-VeeamBackupRepository {
  20.     param ($Token)
  21.  
  22.     $headers = @{
  23.         Authorization = "Bearer $Token"
  24.     }
  25.  
  26.     $backupRepository = Invoke-RestMethod -Method Get -Uri "http://$veeamServer:9419/api/backupRepositories" -Headers $headers
  27.     return $backupRepository
  28. }
  29.  
  30. # Function to get backup files information
  31. function Get-VeeamBackupFiles {
  32.     param ($Token, $RepositoryId)
  33.  
  34.     $headers = @{
  35.         Authorization = "Bearer $Token"
  36.     }
  37.  
  38.     $backupFiles = Invoke-RestMethod -Method Get -Uri "http://$veeamServer:9419/api/backupRepositories/$RepositoryId/backupFiles" -Headers $headers
  39.     return $backupFiles
  40. }
  41.  
  42. # Main Script
  43. try {
  44.     $token = Get-VeeamAuthToken
  45.     $repositories = Get-VeeamBackupRepository -Token $token
  46.  
  47.     # You might need to adjust this part to select the correct repository
  48.     $repositoryId = $repositories[0].id
  49.  
  50.     $backupFiles = Get-VeeamBackupFiles -Token $token -RepositoryId $repositoryId
  51.  
  52.     # Creating a comma-separated list of backup files
  53.     $backupFilesList = $backupFiles | ForEach-Object { "$($_.name), Size: $($_.size)" }
  54.     $backupFilesList -join ", "
  55. } catch {
  56.     Write-Error "An error occurred: $_"
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement