Reputation: 11
I'm a bit stuck here, and by that I mean I'm banging my head against the wall.
I'm trying to create a script that does the following:
Checks files/folders and moves all folders/files older than one day into another folder, whilst keeping the folder structure accurate.
Currently, I have this:
Get-ChildItem -Path $SourceFolder -Recurse |
Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-1)} |
foreach {
Move-Item $AzCopyFolder -Force}}
and I'm really not sure what I'm even doing anymore. It works, but it also copies files inside one of the folders that aren't older than one day. Help would be appreciated.
Thanks.
Upvotes: 0
Views: 384
Reputation: 11
So, after hours of searching and screaming internally, I just used RoboCopy.
robocopy $SourceFolder $DestFolder /e /move /minage:1
Job done. Thank god.
Upvotes: 1