Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Replace these variables with your actual credentials and server details
- $veeamServer = "your_veeam_server"
- $username = "your_username"
- $password = "your_password"
- # Function to authenticate and get the token
- function Get-VeeamAuthToken {
- $authBody = @{
- grant_type = "password"
- username = $username
- password = $password
- }
- $authResponse = Invoke-RestMethod -Method Post -Uri "http://$veeamServer:9419/api/oauth2/token" -Body $authBody
- return $authResponse.access_token
- }
- # Function to get backup repository information
- function Get-VeeamBackupRepository {
- param ($Token)
- $headers = @{
- Authorization = "Bearer $Token"
- }
- $backupRepository = Invoke-RestMethod -Method Get -Uri "http://$veeamServer:9419/api/backupRepositories" -Headers $headers
- return $backupRepository
- }
- # Function to get backup files information
- function Get-VeeamBackupFiles {
- param ($Token, $RepositoryId)
- $headers = @{
- Authorization = "Bearer $Token"
- }
- $backupFiles = Invoke-RestMethod -Method Get -Uri "http://$veeamServer:9419/api/backupRepositories/$RepositoryId/backupFiles" -Headers $headers
- return $backupFiles
- }
- # Main Script
- try {
- $token = Get-VeeamAuthToken
- $repositories = Get-VeeamBackupRepository -Token $token
- # You might need to adjust this part to select the correct repository
- $repositoryId = $repositories[0].id
- $backupFiles = Get-VeeamBackupFiles -Token $token -RepositoryId $repositoryId
- # Creating a comma-separated list of backup files
- $backupFilesList = $backupFiles | ForEach-Object { "$($_.name), Size: $($_.size)" }
- $backupFilesList -join ", "
- } catch {
- Write-Error "An error occurred: $_"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement