Reputation: 1
I need to create a scipt that copies all files and folders from \UNCPathA to \UNCPathB but will MOVE any files (retaining folder structure) older than 1 day.
I know how to do this with multiple RoboCopy scripts, but I want to perform both tasks in a single script if possible (perhaps using PowerShell).
Any help would be greatly appreciated.
Upvotes: 0
Views: 6512
Reputation: 301
I haven't done any testing, but I would probably start with something like this:
$uncA="\\server\share"
$uncB="\\server\share"
foreach ($item in (Get-ChildItem $uncA)) {
If ($item.LastWriteTime -lt ((Get-Date).AddDays(-1))) {
Move-Item $item.FullName $uncB
} Else {
Copy-Item $item.FullName $uncB
}
}
$uncA
and $uncB
can be UNC or Windows paths (or anything that powershell can understand).
Upvotes: 1