Move Files older then 31 days to another drive Move Files older then 31 days to another drive powershell powershell

Move Files older then 31 days to another drive


I don't know if this makes much of a difference, but rather than $. it needs to be $_.

I tried this script and it works fine for me:

get-childitem -Path "E:\source" |    where-object {$_.LastWriteTime -lt (get-date).AddDays(-31)} |     move-item -destination "F:\target"

Notice you don't need a foreach loop because the objects will be "piped" into the move-item command


Also be aware of hidden files, try adding -Force to Get-ChildItem