Last active
June 17, 2021 08:01
-
-
Save mritsurgeon/24aab544411177f946c7097e209eca24 to your computer and use it in GitHub Desktop.
Find Orphaned Backups
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try{$path=($args -match "-path=").substring(6)} | |
catch{Write-host "missing path argument" -fore red} | |
try{$myhost=($args -match "-host=").substring(6)} | |
catch{Write-host "missing host argument" -fore red} | |
if (!$path.contains('\')) { | |
Write-host "suspiscious path provided $path. please use quotes for arguments." -fore red | |
exit | |
} | |
$unc="\\$myhost\"+$path.replace(':','$') | |
try {gci $unc -erroraction stop > $null} | |
catch {write-host "could not browse $unc. please check arguments." -fore red} | |
$age=30 | |
$results = New-Object system.collections.arraylist | |
$myFQDN=(Get-WmiObject win32_computersystem).DNSHostName+"."+(Get-WmiObject win32_computersystem).Domain | |
$myFQDN=$myhost+"."+(Get-WmiObject win32_computersystem).Domain | |
$backup = Get-VBRBackup | ?{$_.jobtype -eq "Backup"} | |
$Backup.GetAllStorages() |% { | |
if ($_.CreationTime -gt (get-date).adddays(-$age)) { | |
$AgeWarning = "Ok" } | |
else { $AgeWarning = ">$age days"} | |
$object = [PSCustomObject]@{ | |
Repo = $_.findHost().Name | |
FilePath = $_.filePath | |
Created = $_.CreationTime | |
SizeKB = $_.stats.backupsize/1024 | |
GFSPeriod = $_.GFSPeriod | |
Age = $AgeWarning | |
} | |
$results.add($object) > $null | |
} | |
$target=($results|Where-Object {$_.repo.toupper() -eq $myFQDN.toupper()}|sort FilePath) | |
$results = New-Object system.collections.arraylist | |
foreach ($l in (ls -path $unc -Recurse -include *vib,*vbk | select-object fullname,name)) { | |
if($target -match $l.name){$FoundNotFound="Found"} | |
else {$FoundNotFound="NOT Found"} | |
$object = [PSCustomObject]@{ | |
FilePath = $l.FullName | |
Found = $FoundNotFound | |
} | |
$results.add($object) > $null | |
} | |
$target | out-gridview -title "Restore Points on $myFQDN" | |
$results | out-gridview -title "VIB/VBK files in $unc" | |
#Witten By Jean Pierre Verland |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment