troubleshooting Question

How to count the number of days since a file has been touched against todays'date

Avatar of namerg
namergFlag for United States of America asked on
14 Comments2 Solutions421 ViewsLast Modified:
I would like to know how to count the number of days/months that a file has been modified.
For example if file xyx was modified on March 31 and is withing the range of 30 days/1 month, it is ok. But, if the file was modified or last touch on Feb 28, hmm there is a problem.
I have this code but I am stuck.
$now = Get-Date
#$strDate = "{0:yyyyMMdd}" -f ($now)
#$now = $now.ToString("MMddyyyy")

$folder = "\\jupiter\Shared\PA\ARS\REMITS"
#$files0 = gci $folder | Where-Object {$_.LastWriteTime.ToString("yyyyMMdd") -lt $strDate }
$files0 = gci $folder | ForEach-Object { ($_.LastWriteTime)}
foreach ($strDates in $files0)
 $difference = $now - $strDates
#if $files0.LastWritetime
#$days = $now - $files0.LastWriteTime
$Bingo = 1
Subash Sundharan
IT Infrastructure Architect

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 14 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 14 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros