Solved

Powershell script to move files

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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

634 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