Solved

Powershell script to move files

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

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 68

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now