Getting the configured Backup on Windows Server 2008 R2 machines remotely using powershell

Hi

Sometimes you need to solve a problem in downlevel O.S where the commandlets for the task you want are not available. Today was one of these days, one customer asked me… ¿how can I know if I configured properly a bare metal backup of all my 2008r2 domain controllers? Let see how we did it in a quick and dirty (but working way)

First we used the parallexecution module, if you do not know what this is look here: https://blogs.technet.microsoft.com/fernandorubio/2018/01/25/powershell-remoting-made-easy-with-parallelexecution-module/

to get using wbadmin the list of backups performed on all the domain controllers in the forest

$domains=(Get-ADForest).domains

$dcs=@()

foreach ($domain in $domains){

$dcs+=get-addomaincontroller -filter * -server $domain

}

$dcnames = $dcs| Select -ExpandProperty hostname

$results=$dcnames | start-parallelexec -command "wbadmin get versions" -Verbose

 

This is great, the info we want is there but the result of wbadmin is text we need to parse so we iterate the hashtable, creating an array of tempobjects (one per each backup per DC) and add it as a new custom property to the hashtable.

 

foreach ($dc in $results.GetEnumerator()){

$text=$dc.Value.results

$textlenght=$text.Count

$backuparray=@()

for ($i=3;$i -lt $textlenght;$i=$i+$depends){

$tempobject=New-Object -TypeName psobject

$tempobject | Add-Member -MemberType NoteProperty -Name "backuptime" -Value $text[$i]

$tempobject | Add-Member -MemberType NoteProperty -Name "backuplocation" -Value $text[$i+1]

$tempobject | Add-Member -MemberType NoteProperty -Name "versionidentifier" -Value $text[$i+2]

$tempobject | Add-Member -MemberType NoteProperty -Name "contents" -Value $text[$i+3]

$tempobject | Add-Member -MemberType NoteProperty -Name "computername" -Value $dc.Key

if ($text[$i+4] -ne ""){

$tempobject | Add-Member -MemberType NoteProperty -Name "snapshotid" -Value $text[$i+4]

$depends="6"

}

else{

$depends="5"

}

$backuparray+=$tempobject

}

$dc.Value | Add-Member -MemberType NoteProperty -Name "backupsparsed" -Value $backuparray

}

That is, now we have a new property in our hash table with the parsed backup info. So for example to see if there are DCs that do not have performed bare metal backups we can simply run

$results.values.backupsparsed | where contents -NotLike "*bare*" | select computername -Unique

Piece of cake, a problem solved in 30 minutes that without powershell would have taken ages…

Hope you found it interesting!

Fernando Rubio