itunplugged
IS-IT--Management
Hi, I'm trying to put together a quick script to moves files that meet a date criteria to another folder. I have managed to get the below script to work (I'm a newbie if you haven't already guessed);
Function DNCRRequestArchive {
#Moves all files older than 2 days old from the Request folder to the Request Archive
dir "C:\DNCR Root\RequestFolder" |
where-object { $_.LastWriteTime -lt (get-date).AddDays(-2)} | move-item -destination "D:\DNCR Archive\Request" -force -ErrorAction:SilentlyContinue }
DNCRRequestArchive
But it uses far to much memory as I am running the script against 20,000 files. So I've tried to use the foreach pipe however it keeps asking me for a move-item path, the script I'm using is below, can any one help me please?
Function DNCRRequestArchive {
#Moves all files older than 2 days old from the Request folder to the Request Archive
Get-ChildItem -Path "C:\DNCR Root\RequestFolder" |
where-object { $_.LastWriteTime -lt (get-date).AddDays(-2)} |
Foreach {move-item -destination "D:\DNCR Archive\Request" -force -ErrorAction:SilentlyContinue} }
DNCRRequestArchive
Thanks,
Nick
Function DNCRRequestArchive {
#Moves all files older than 2 days old from the Request folder to the Request Archive
dir "C:\DNCR Root\RequestFolder" |
where-object { $_.LastWriteTime -lt (get-date).AddDays(-2)} | move-item -destination "D:\DNCR Archive\Request" -force -ErrorAction:SilentlyContinue }
DNCRRequestArchive
But it uses far to much memory as I am running the script against 20,000 files. So I've tried to use the foreach pipe however it keeps asking me for a move-item path, the script I'm using is below, can any one help me please?
Function DNCRRequestArchive {
#Moves all files older than 2 days old from the Request folder to the Request Archive
Get-ChildItem -Path "C:\DNCR Root\RequestFolder" |
where-object { $_.LastWriteTime -lt (get-date).AddDays(-2)} |
Foreach {move-item -destination "D:\DNCR Archive\Request" -force -ErrorAction:SilentlyContinue} }
DNCRRequestArchive
Thanks,
Nick