SSAS Analysis Backup History Table Data insert

I need some script to insert data(Success Information/Failure Information) into a DB Engine Table if   $database.Backup("$directory_path\$database-$timestamp.abf") statement got executed successful/Failure

Table Contains(Servername,Getdate(),Backuplocation,Status) fields

please suggest.

 

 

$server_name = $null
 
$backup_location = "K:\Analysis_Test"
 
$user_requested_databases = "Test2"
 
$retention_period_in_days = 7

if ($server_name -eq $null)
 {
  $server_name = "XXXXX"
 
}
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices") | out-null
$server = New-Object Microsoft.AnalysisServices.Server
$server.connect($server_name)

if ($backup_location -eq $null)
{
$backup_location = ($server.get_ServerProperties() | Where {$_.Name -eq "BackupDir"}).Value
}
 
elseif (!(Test-Path -path $backup_location))
{
 throw "Specified path ($backup_location) does not exist."
}

# Generate an array of databases to be backed up
 $available_databases = ($server.get_Databases() | foreach {$_.Name})
 if ($user_requested_databases -eq $null) {
  $databases = $available_databases}
 else {
  $databases = $user_requested_databases.Split(",")
  # Check that all specified databases actually exist on the server.
  foreach ($database in $databases) {
   if ($available_databases -notcontains $database) {
    throw "$database does not exist on specified server."
   }
  }
 }

 foreach ($database in ($server.get_Databases() | Where {$databases -contains $_.Name})) {
  $directory_path = $backup_location + "\" + $database.Name
  if (!(Test-Path -Path $directory_path)) {
   New-Item $directory_path -type directory | out-null
  }
  [string] $timestamp = date
  $timestamp = $timestamp.Replace(':','').Replace('/','-').Replace(' ','-')
  $database.Backup("$directory_path\$database-$timestamp.abf")
        
  # Cleanup Old Backups
  Get-ChildItem $directory_path | where {
   $_.LastWriteTime -le (Get-Date).AddDays(-$retention_period_in_days)
  } | remove-item
 }

$server.disconnect()