Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving files from one volume to another.... 1

Status
Not open for further replies.

itunplugged

IS-IT--Management
Aug 17, 2009
2
AU
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
 
I think you're missing the full path of the file(s) you wish to move:

Code:
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 [b]$_.FullName[/b] -destination "D:\DNCR Archive\Request" -force -ErrorAction:SilentlyContinue
  }
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top