查找文件/文件夹的修改日期 [英] Finding modified date of a file/folder

查看:136
本文介绍了查找文件/文件夹的修改日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对PowerShell还是很陌生,希望可以帮助我创建一个脚本,该脚本告诉我文件的修改日期.

I am very new to PowerShell, and I was hoping I could get some help creating a script that tells me the modified date of a file.

我希望我对PowerShell有了更多的了解,因为我觉得自己提出了很多要求(本周我所有的业余时间都将致力于更好地学习PowerShell).为我指明在何处学习如何执行此操作也将非常有帮助.

I wish I knew more about PowerShell, as I feel like I am asking a lot (all my free-time this week will be dedicated to learning PowerShell better). Pointing me in the direction of where to learn how to do this would be very helpful as well.

这是完整的摘要.我需要每天运行一份报告,检查90个不同商店中的计算机列表,以确保已执行特定备份.修改后的日期应告诉您是否已执行备份,并将其设置为以前的日期.

Here is the complete rundown. I need to run a report daily that checks a list of computers at 90 different stores to make sure their a certain backup was performed. The modified date should tell if the backup had been performed, and will be set to the previous date.

如果修改日期是昨天,则不需要输出.如果不是昨天,我希望将输出显示在PowerShell窗口或文本文件中,以较容易的一个为准.

If the modified date is yesterday, then there does not need to be an output. If it is not yesterday, I would like to have the output in the PowerShell window, or to a text file, whichever would be easier.

对于90个商店中的每个商店,我还必须检查文件夹是否不超过7天,并且输出标准相同.我对每个商店的想法都是这样

I also have to check that a folder is no older than seven days for each of the 90 stores, with the same criteria for the output. The idea that I have would be like this for each store

对于商店1:

Check file date for \\server\store\computer\c:\folder\"newest modified date in folder"
if date equals yesterday
   then do nothing
if date does not equal yesterday
   then output "Test did not backup"

check folder modified date for \\server\sample\store\backupfolder
if date equals <7 days old
   then do nothign
if date equals >7 days old
   then output "test did not backup"

很抱歉,我还没有证明自己的研究工作,因此我对Powershell来说还很陌生,而且我正赶在最后期限之前完成这项工作.从昨天开始,我学习了如何使用该脚本进行所需的所有操作.感谢@Keith为我设置了正确的路径.我最终使用以下代码来实现我的目标,即只输出结果为假的位置.

Sorry for not proving my research effort, I am very new to Powershell and I was on a deadline to get this done. I have, since yesterday, learned how to do everything that I needed to do with this script. Thanks to @Keith for setting me on the correct path. I ended up using the following code to accomplish my goal of only out-putting the location where result was false.

$a = Get-ChildItem \\server\XXX\Received_Orders\*.* | Where{$_.LastWriteTime -ge (Get-Date).AddDays(-7)}
if ($a = (Get-ChildItem \\server\XXX\Received_Orders\*.* | Where{$_.LastWriteTime -ge (Get-Date).AddDays(-7)}))
{
}
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 -ge (Get-Date).AddDays(-1)}))
{
}
Else
{
    'STORE XXX DID NOT RUN ITS BACKUP LAST NIGHT'
}

推荐答案

如果运行Get-Item或Get-ChildItem命令,这些命令将输出System.IO.FileInfo

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)}

这篇关于查找文件/文件夹的修改日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆