Solved

Powershell to move files with a "Date Modified" date more recent than 06/01/2016

Posted on 2016-08-07
3
20 Views
Last Modified: 2016-08-07
Hi, this is actually a 2 part question, although I am sure the first one can be answered extremely easily.

1. How can I get a list of all files within a folder on a server? (I would like to know how to do this for one specific folder as well as for all sub-folders, with the output showing the directory that the file is in)

2. How can I move all .tif files within a folder that have a "Date Modified" date more recent than 06/01/2016 to a separate folder? This also is on a server.

Thanks!
0
Comment
Question by:Brent Guttmann
  • 2
3 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 41746319
1a. Within a folder:
Get-ChildItem C:\Windows

Open in new window


1b. Within a folder and subfolders:
Get-ChildItem C:\Windows -Recurse

Open in new window


The most important command in PS:
Get-Help <Cmdlet>

2. Move the items; the Move-Item is in test mode and will only display what it would do, but not actually move anything. Remove the -WhatIf argument to run it for real.
$NewerThan = Get-Date -Date "06/01/2016"
Get-ChildItem C:\Temp -Filter *.tif -Recurse | ? {$_.LastWriteTime -ge $NewerThan} | Move-Item -Destination D:\Target -WhatIf

Open in new window

0
 
LVL 83

Expert Comment

by:oBdA
ID: 41746326
Oh, and in case you want the listing in table format, for example with LastWriteTime:
Get-ChildItem C:\Temp | Select FullName, LastWriteTime

Open in new window

And to write that to a file:
Get-ChildItem C:\Temp | Select FullName, LastWriteTime | Export-Csv C:\Temp\DirectoryList.csv -NoTypeInformation

Open in new window

To get a list of the properties you can select for an object, get an object of interest and pipe it to Get-Member:
Get-Item C:\Windows\notepad.exe | Get-Member

Open in new window

0
 

Author Comment

by:Brent Guttmann
ID: 41746353
Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Synchronize a new Active Directory domain with an existing Office 365 tenant
This article will help you understand what HashTables are and how to use them in PowerShell.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

20 Experts available now in Live!

Get 1:1 Help Now