Solved

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

Posted on 2016-08-07
3
18 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 82

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 82

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Set OWA language and time zone in Exchange for individuals, all users or per database.
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

12 Experts available now in Live!

Get 1:1 Help Now