Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Comparing dates and then archive files greater than 14 days

$
0
0

Hello all
Need some help please. I need to retrieve the contents of various folders and then check the lastWriteTime. If it is greater than 14 days old I need to move the item into an archive folder. I am getting stuck on comparing the dates and then moving the files. This is what I currently have

$date = get-date
$PathToGo = “F:\Scripts\Paygate\Archive”

write-host “Now connecting to remote storage location”
start-sleep 3
#new-psdrive -name PayGate -psProvider FileSystem -Root F:\Scripts\Paygate
Get-PSDrive -name PayGate -PSProvider FileSystem

[int]$Count = 0
$Location = (get-psdrive Paygate).root
$SearchFolders = Get-ChildItem F:\Scripts\Paygate -Recurse | ForEach {$_.FullName}
$PaymentList = $SearchFolders
[int]$TotalPayment = ($SearchFolders | Measure-object).count
write-host “There are a total of $TotalPayment found.”

$lastwriteTime = (Get-Item $PaymentList).LastWriteTime
write-host $lastWriteTime

Compare-Object $b $date

ForEach ($Payment in $PaymentList)
{
copy-item $payment $PathToGo
}


Viewing all articles
Browse latest Browse all 13067

Trending Articles