Okay I have the hard part done, I've got it calculating the right age of files, but when I loop through my folders it's losing it...and I'm not seeing why? Basically I'm searching a directory that contains a bunch of subdirecotries, and in each subdirectory I'm looking for a FULL backup that is older than 2 Fridays and moving that to an archive folder.
The problem is when it loops through the folders it's messing up my $ADir. For example it show $ADir as "C:\Backups\_Archives\C:\Backups\folder1" when it should say "C:\Backups\_Archives\folder1".
$LSDir = "C:\Backups\" # LogShip Directory
$ADir = "C:\Backups\_Archives" # Archive Directory
$Today = Get-Date # Todays Date
$GoBack = $Today.DayOfWeek.value__
$Days = 7 + ($GoBack-5) # Number of days between today and last Friday
$Old = $Today.AddDays(-$Days) # 2 Previous Fridays ago
# Get list folders (excluding _* and Login folders)
$Folders = Get-ChildItem $LSDir -Exclude _*,Login* | Where { $_.PsIsContainer }
Write-Host "Beginning to process backups for" $Folders.Count "folders..."
# For every folder archive backups older than $Old
ForEach ($Folder in $Folders)
{
Write-Host "Moving FULL Backups older than $Old from $Folder to $Adir\$Folder.BaseName";
# Get $Old FULL backups for this folder and move to $ADir
Get-ChildItem $Folder.FullName -Exclude *DIFF*,*LOG*,*.ldt | Where { $_.LastWriteTime -le $Old } | Move-Item -Destination $Adir"\"$Folder.Name
}