Powershell - Get-RecoveryPoints for all protected machines?

Hi,

I see that it is possible to get a list of all recovery points for a protected machine:

Get-RecoveryPoints -protectedserver [servername] -Number all

This list shows both BASE and Incremental recovery points which is great :-)

However I am looking for a way to display this list on all protected machines at the Core, to find all the BASE images taking up space.

Does anyone know if this is possible in stead of making the list one by one on each protected machine ?

Thanks.

  • There is no option to do that with the PowerShell command directly, however, there is a script that helps with that task. Test it out in your environment, it will run and create a report with the list of each base image. Hope this helps.

    param(
    $reportpath="$env:userprofile\Downloads\$($env:computername)_$([guid]::NewGuid()).html",
    $mytitle='Rapid Recovery Base Images Report'
    )
    function convert-bytes{
    param($bytevalue)
     $size = [long]$bytevalue
     Switch ($Size)
     {
     {$Size -gt 1PB} {$NewSize = “$([math]::Round(($Size / 1PB),2))PB”;Break}
     {$Size -gt 1TB} {$NewSize = “$([math]::Round(($Size / 1TB),2))TB”;Break}
     {$Size -gt 1GB} {$NewSize = “$([math]::Round(($Size / 1GB),2))GB”;Break}
     {$Size -gt 1MB} {$NewSize = “$([math]::Round(($Size / 1MB),2))MB”;Break}
     {$Size -gt 1KB} {$NewSize = “$([math]::Round(($Size / 1KB),2))KB”;Break}
     Default {$NewSize = “$([math]::Round($Size,2))Bytes”;Break}
     }
     return $newsize
     
    }
    
    function set-title {
    param($mytitle='Rapid Recovery Base Images Report',$startdate,$enddate,$logo)
    
    return @"
    <table style="Width:100%">
    <tr><td colspan="3" style="text-align:right;" >$($logo)</td></tr>
    <tr><td colspan="3" style="font: 20px Arial, Helvetica, sans-serif;font-weight: 900;color:darkred" >$($mytitle)</td></tr>
    <tr><td style="font-weight: 900;text-decoration:underline;width:250px">Core</td><td style="font-weight: 900;text-decoration:underline;width:250px">Generated On</td><td></td></tr>
    <tr><td>$($env:computername)</td><td>$($enddate.tostring("ddd MM/dd/yyyy hh:mm:ss tt"))</td></tr>
    "@
    }
    function do-restcall{
    param(
    $uriend=$null, 
    $corename=$env:computername, 
    $method="GET", 
    $ContentType=$null, 
    $credential=$null, 
    $body=$null, 
    $timeoutsec=3600, 
    $port=8006,
    [switch]$myerrormessage
    )
    if($myerrormessage.IsPresent){
    $emessage = "`nERROR`nREST Call on -URI `"https://$($corename):$($port)/apprecovery/api/core/$uriend`" with -Method $method has failed" 
    }else{$emessage=$null}
    $returnedobject=$null
    $uri="https://$($corename):$($port)/apprecovery/api/core"
    
    if($method -eq "GET"){
    try{
    $wc = New-Object System.Net.WebClient
    if($credential){$wc.Credentials = $credential}else{$wc.usedefaultcredentials=$true}
    [System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }
    [xml]$returnedobject =  $wc.DownloadString("$($uri)/$($uriend)")
    }catch{Write-Host "$emessage `r" -f Red;return $null }
    [System.Net.ServicePointManager]::ServerCertificateValidationCallback = $null
    return $returnedobject
    }
    
    $defaultcredstring=$null
    if(!($credential)){$defaultcredstring = "-usedefaultcredential"}else{$defaultcredstring="-Credential `$credential"}
    
    $typestring=$null
    if($contenttype){$typestring="-ContentType `"$($ContentType)`""}
    
    $bodystring=$null
    if($body){$bodystring = "-body `$body"}
    
    $restmethod= @"
    try{ 
    Invoke-RestMethod -URI "$uri/$uriend" -Method $method -Timeoutsec $timeoutsec $defaultcredstring $typestring $bodystring -ErrorAction stop
    }
    catch{Write-Host "$emessage `r" -f RED; return $null}
    "@
    
    $sb=[Scriptblock]::Create($restmethod)
    [System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }
    [xml]$returnedobject = Invoke-Command -ScriptBlock $sb
    [System.Net.ServicePointManager]::ServerCertificateValidationCallback = $null
    return $returnedobject
    }
    function pageheader {
    $htmlhead = @"
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <style>
    body{
    background: grey;
    text-align: left;
    font: 13px Arial, Helvetica, sans-serif;
    }
    table {
    	border-width: 2px;
    	border-spacing: 0px;
    	border-style: solid;
    	border-collapse: collapse;
    border-color:grey;
    width:100%;
    }
    table th {
    	font: 10px Arialbold, Helvetica, sans-serif,;
    	text-align:left; 
    	border-width: 2px;
    	border-spacing: 0px;
    	border-style: solid;
    background-color:grey;
    border-color:grey;
    }
    table td {
    	font: 12px Arial, Helvetica, sans-serif;
    	border-width: 2px;
    	text-align:left; 
    	border-spacing: 0px;
    	border-style: solid;
    
    border-color:white;
    
    }
    
    table tr {
    background-color: White;
    
    }
    
    .agenttable tr:nth-child(odd) {
      background-color: #dfe7f2;
      color: #000000;
    }
    
    .agenttable tr:nth-child(even) {
      background-color: lightgrey;
      color: #000000;
    }
    
    .rptable tr {background-color: White;}
    .rptable th {font-size:12px;font-weight: 900;}
    
    a{font-weight:bold;}
    
    .baseimage {border-width: 0px;border-collapse: collapse;width:100%;margin: 0 0 0 0;font-family:Arial, Helvetica, sans-serif;font-size:10px;padding:0px}
    
    
    /* unvisited link */
    a:link {color: black;}
    
    /* visited link */
    a:visited {color: black;}
    
    /* mouse over link */
    a:hover {color: hotpink;}
    
    /* selected link */
    a:active {color: darkgrey;}
    
    input[type=button], input[type=submit], input[type=reset] {
        background-color: white;
        color: black;
        border: 2px solid grey;
        padding: 4px 8px;
        text-decoration: none;
        margin: 2px 1px;
        cursor: pointer;
        border-radius: 12px;
    }
    
    input[type=button]:hover {
        background-color: grey; 
        color: white;
    }
    
    .statusOK {color:green;font-weight:800;}
    .statusFail {color:red;font-weight:800;}
    
    </style>
    
    </head><body>
    
    "@
    return $htmlhead
    }
    
    #region get-agents
    $agents = (do-restcall -uriend 'agents').agents.agent | select-object displayname,agentType,id,repositoryName
    #endregion
    
    #region get recovery points for each agent
    $rplist = @()
    foreach($agent in $agents){
    Write-Host "Getting Recovery points for agent: $($agent.displayname)"
    [array]$rps = (do-restcall -uriend "recoveryPoints/agents/$($agent.Id)/all").recoverypointsummaries.recoverypointsummary | where {$_.status -like "*Base*"} | sort-object -Property timestamp | select-object @{n="Volumes";e={"$($_.volumeimages.volumeimagesummary.volumedisplayname -join ',')"}},status,@{n='timestamp';e={((get-date($_.timestamp)).ToLocalTime()).tostring('yyyy-MM-dd HH:mm:ss')}},@{n='size';e={(convert-bytes -bytevalue $_.size)}}
    $rplist += [pscustomobject]@{agentname=$agent.displayname;type=$agent.agenttype;agentrepo=$agent.repositoryName;count=$rps.count;rpinfo=$rps}
    }
    Write-Host "`nBuilding agregated list of agents and recovery points." -ForegroundColor Yellow
    "`rAgregated list of agents and recovery points:" 
    #endregion
    #$rplist | ft -AutoSize | out-string 
    
    #region initialization
    $enddate = Get-Date
    $startdate = $enddate.AddDays((-1)*$days)
    
    $path= split-path -path $reportpath -Parent
    if(!(Test-Path $path)){
    write-host "`nPath does not exist. Attempting to create..." -f Yellow
    New-Item -Path $path -ItemType directory}
    $file = split-path -path $reportpath -leaf
    $filename = [System.IO.Path]::GetFileNameWithoutExtension($file)
    $fileextension=[System.IO.Path]::GetExtension($file)
    $reportpath="$($path)\$($filename)_$($enddate.tostring(`"yyyy-MM-dd`"))$($fileextension)";
    $null > $reportpath 
    #endregion
    
    #region starting the html report
    $logo=''
    $title = set-title -mytitle $mytitle -logo $logo -startdate $startdate -enddate $enddate
    $h = pageheader
    $h += "<a name=top></a><table><tr><td><h2>$($title)</h2></td></tr></table></br>"
    #endregion
    $h +=@"
    <table class="rptable"><tr><th>Agent</th><th>Type</th><th>Repository</th><th>Base Image Count</th></tr>
    "@
    $atable=''
    foreach($rp in $rplist){
    
    $atable +=@"
    <tr><td colspan="4"> </td></tr>
    <tr><td rowspan="2" style="font-size:12px;font-weight: 900;">$($rp.agentname)</td><td>$($rp.type)</td><td>$($rp.agentrepo)</td><td>$($rp.count)</td><tr>
    <tr><td></td><td colspan="3"><table class="agenttable"}><tr><th>Volumes</th><th>Status</th><th>Timestamp</th><th>Size</th></tr>
    $(foreach($line in $rp.rpinfo){"<tr><td>$($line.volumes)</td><td>$($line.status)</td><td>$($line.timestamp)</td><td>$($line.size)</td></tr>"})
    </table></td></tr>
    "@
    
    
    }
    
    $h +="$($atable)</table>"
    $h | out-file -filePath $reportpath -Append
    invoke-item $reportpath