Solved

Powershell script to move files

Posted on 2015-01-12
2
114 Views
Last Modified: 2015-01-13
I see the cmdlet move-item, and wonder how I can move files based on age (>4 years) or I guess conversely not move files that have been accessed in the last 4 years or less.

Thx!
0
Comment
Question by:SquigglyMonkey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 29

Accepted Solution

by:
becraig earned 500 total points
ID: 40545532
You can utilize
CreationTime
or
LastWriteTime

simply  go a recursive get child item then find files matching the required date and do your move:
gci C:\folder -recurse | ? {!($_.psiscontainer) -and $_.CreationTime -lt (Get-date).AddDays(-400)}

Open in new window


same for LastWriteTime
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 40545533
You first get all objects with get-childitem, then filter with where-object for age, and pipe the remaining objects to move-item. The difficult part is to replace the root part of the source by the target root ...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question