PowerShell script to move files and folders including subfolders from one location to another older than x days PowerShell script to move files and folders including subfolders from one location to another older than x days powershell powershell

PowerShell script to move files and folders including subfolders from one location to another older than x days


Don't waste your time trying to re-invent robocopy in PowerShell.

robocopy \\servername\location C:\Dumps /e /mov /minage:31


Use the -Recurse option on the Get-ChildItem command to get through to the files in the sub folders and then move each individually by piping the collection to Move-Item

Get-ChildItem -Path "C:\Test" -Recurse |  Where-Object {$_.LastWriteTime -lt (Get-date).AddDays(-31)} |  Move-Item -destination "C:\Dumps"

Here's a screenshot:

screenshot


Simplification of the above
robocopy A:\ B:\ /MIR /minage:31
Where A:\ is your sourceB:\ is your destination