Solved

Powershell script to move files

Posted on 2015-01-12
2
111 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
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 69

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
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ā€¦

679 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