[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2016-08-07
3
Medium Priority
?
33 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 85

Accepted Solution

by:
oBdA earned 2000 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 85

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. 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

In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
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 anti-spam), the admin…
Screencast - Getting to Know the Pipeline

872 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