Powershell script to list all backups in a location
NOTE: There are a few assumptions with this script.
1 - There is an xml file created containing the credentials for a user that has access to the ASN server
Example: Get-Credential | Export-CliXML - Path C:\Users\AcronisUser\Desktop\Credential.xml
2 - The path to the xml file and the location information in the acrocmd commands are modified with accurate information
3 - This script is run on the server with ASN installed
$username = $((Import-Clixml -Path <Drive_Letter:\Path\To\Credential.xml>).UserName)
$password = $((Import-Clixml -Path <Drive_Letter:\Path\To\Credential.xml>).GetNetworkCredential().Password)
$Archives = acrocmd list archives --loc bsp://<StorageNode_Server_Name>/<Vault_Name> --credentials=$username,$password --all --output=raw
$ArchiveArray = @()
ForEach ($Archive in $Archives)
{
If ($Archive -ne "The operation completed successfully.")
{
If ($Archive -ne "")
{
$objArchive = New-Object PSObject -Property @{
Name = $(($Archive -split "`t")[0])
Type = $(($Archive -split "`t")[1])
Date_Created = $([DateTime]::ParseExact($(($Archive -split "`t")[2]),'dd.MM.yyyy HH:mm:ss',$null))
Backed_Up_Device = $(($Archive -split "`t")[3])
Owner = $(($Archive -split "`t")[4])
Archive_Size = "$([Math]::Round(((($Archive -split "`t")[5]) / 1MB),2)) MB"
Archive_Comments = $(($Archive -split "`t")[6])
Password_Protected = $(($Archive -split "`t")[7])
Data_Size = "$([Math]::Round(((($Archive -split "`t")[8]) / 1MB),2)) MB"
}
$ArchiveArray += $objArchive
}
}
}
$BackupArray = @()
ForEach ($Archive in $ArchiveArray)
{
$Backups = acrocmd list backups --loc bsp://<StorageNode_Server_Name>/<Vault_Name> --credentials=$username,$password --arc=$($Archive.Name) --output=raw
ForEach ($Backup in $Backups)
{
If ($Backup -ne "The operation completed successfully.")
{
If ($Backup -ne "")
{
$objBackup = New-Object PSObject -Property @{
Archive_Name = $($Archive.Name)
Archive_Type = $($Archive.Type)
Archive_Date_Created = $($Archive.Date_Created)
Backed_Up_Device = $($Archive.Backed_Up_Device)
Owner = $($Archive.Owner)
Archive_Size = $($Archive.Archive_Size)
Archive_Comments = $($Archive.Archive_Comments)
Archive_Password_Protected = $($Archive.Password_Protected)
Archive_Data_Size = $($Archive.Data_Size)
Backup_GUID = $(($Backup -split "`t")[0])
Backup_Type = $(($Backup -split "`t")[1])
Backup_Password_Protected = $(($Backup -split "`t")[2])
Backup_Date_Created = [DateTime]::ParseExact($(($Backup -split "`t")[3]),'dd.MM.yyyy HH:mm:ss',$null)
Backup_Data_Size = "$([Math]::Round((((($Backup -split "`t")[4]).Trim(' bytes') -replace ',','') / 1MB),2)) MB"
}
$BackupArray += $objBackup
}
}
}
}
$BackupArray = $BackupArray | Select-Object -Property Backed_Up_Device,Archive_Name,Archive_Type,Archive_Date_Created,Archive_Size,Archive_Data_Size,Archive_Comments,Archive_Password_Protected,Owner,Backup_GUID,Backup_Type,Backup_Password_Protected,Backup_Date_Created,Backup_Data_Size | Sort-Object -Property Backed_Up_Device,Archive_Name,Backup_Date_Created
#Once all of the backups' information have been gathered, you can filter them by property value and perform actions against them.
#Example: Filter backups older than 30 days and delete them
#$FilteredBackups = $BackupArray | Where-Object {$_.Backup_Date_Created -le $(Get-Date).AddDays(-30)}
#ForEach ($Backup in $FilteredBackups)
# {
# acrocmd delete backup --loc bsp://<StorageNode_Server_Name>/<Vault_Name> --credentials=$username,$password --arc=$($Archive.Name) --backup=$($Backup.Backup_GUID)
# }


- Log in to post comments