Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Within the first afternoon I found 2 of the 3 needed solutions, and the 3rd came to me over the weekend!..."

Geography

Where in the world do Tek-Tips members come from?

Moving files from one volume to another....Helpful Member! 

itunplugged (IS/IT--Management)
17 Aug 09 4:13
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
Helpful Member!  brigmar (Programmer)
17 Aug 09 9:46
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 $_.FullName -destination "D:\DNCR Archive\Request" -force -ErrorAction:SilentlyContinue
  }
}
itunplugged (IS/IT--Management)
17 Aug 09 19:09
Thanks brigmar! Your a star!

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close