0

I have this line of code to move files and folders over a certain age to another folder

But it doesnt work, I run it but it just goes back to a prompt

Get-ChildItem -Recurse c:\test | where-Object {$_.Creationtime -lt (Get-Date).AddMonths(-6)} | ForEach-Object { robocopy "c:\test" "c:\old" /Z /S  } 

1 Answer 1

1

Edit: only robocopy

robocopy "c:\test" "c:\old"  /Z /S /MINAGE:yyyymmdd (or /MINAGE:<numbers of days>)
Sign up to request clarification or add additional context in comments.

14 Comments

Will not work correctly, you need $_.Fullname instead of "c:\test\$($_.name)"
Christian thanks for your help, but that doesnt work either...its like the robocopy part isnt running. I tried running the Robocopy from the cmd line and that works fine on its own
Ocaso, do you mean like this "c:\test\$_.Fullname)" ?
First, do you really need Robocopy? Second, do you really want to move folders created before a certain date? The folders might contain newer files? Or do you really just want to move old files and retain the directory structure?
@OcasoProtal Sure! The problem here is using robocopy as Jeffery say is not the best way mixing with powershell
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.