Skip to content

Instantly share code, notes, and snippets.

@tdewin
Created July 11, 2018 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdewin/5c117df03d866c39913df43f71b11ba2 to your computer and use it in GitHub Desktop.
Save tdewin/5c117df03d866c39913df43f71b11ba2 to your computer and use it in GitHub Desktop.
Check retention of Veeam files and do something with it
$retDays = 14
$path = "c:\myrepository\"
$prevDate = (get-date).AddDays(-$retDays)
$filesDir = get-childitem -Path $path -Recurse -Include "*.vbk","*.vib" -File
$listrm = @()
foreach ($file in $filesDir) {
$fname = $file.FullName
if($file.Name -match "(20[0-9]{2}-[0-9]{2}-[0-9]{2}T[0-9]{6})[.](vib|vrb|vbk)") {
$pointdate = [System.DateTime]::ParseExact($Matches[1],"yyyy-MM-ddTHHmmss",$null)
if($pointdate -lt $prevDate) {
if($file.LastWriteTime -lt $prevDate) {
write-host "Adding to list $fname ($pointdate)"
$listrm += $file
} else {
write-host "Not in retention but last access time is still before $prevdate $fname"
}
} else {
write-host "Still in retention $fname"
}
} else {
write-error ("Could not match $fname" )
}
}
foreach ($rmfile in $listrm) {
$rmfname = $rmfile.FullName
write-host "Do something here with $rmfname"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment