Finding modified date of a file/folder Finding modified date of a file/folder powershell powershell

Finding modified date of a file/folder


If you run the Get-Item or Get-ChildItem commands these will output System.IO.FileInfo and System.IO.DirectoryInfo objects that contain this information e.g.:

Get-Item c:\folder | Format-List  

Or you can access the property directly like so:

Get-Item c:\folder | Foreach {$_.LastWriteTime}

To start to filter folders & files based on last write time you can do this:

Get-ChildItem c:\folder | Where{$_.LastWriteTime -gt (Get-Date).AddDays(-7)}


To get the modified date on a single file try:

$lastModifiedDate = (Get-Item "C:\foo.tmp").LastWriteTime

To compare with another:

$dateA= $lastModifiedDate $dateB= (Get-Item "C:\other.tmp").LastWriteTimeif ($dateA -ge $dateB) {  Write-Host("C:\foo.tmp was modified at the same time or after C:\other.tmp")} else {  Write-Host("C:\foo.tmp was modified before C:\other.tmp")}


Here's what worked for me:

$a = Get-ChildItem \\server\XXX\Received_Orders\*.* | Where{$_.LastWriteTime -ge (Get-Date).AddDays(-7)}if ($a = (Get-ChildItem \\server\XXX\Received_Orders\*.* | Where{$_.LastWriteTime -gt (Get-Date).AddDays(-7)}  #Im using the -gt switch instead of -ge{}Else{'STORE XXX HAS NOT RECEIVED ANY ORDERS IN THE PAST 7 DAYS'}$b = Get-ChildItem \\COMP NAME\Folder\*.* | Where{$_.LastWriteTime -ge (Get-Date).AddDays(-1)}if ($b = (Get-ChildItem \\COMP NAME\TFolder\*.* | Where{$_.LastWriteTime -gt (Get-Date).AddDays(-1)))}{}Else{'STORE XXX DID NOT RUN ITS BACKUP LAST NIGHT'}