PowerShell脚本求的文件/文件夹的修改日期 [英] Powershell Script for Finding Modified Date of a file/folder

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

问题描述

我很新的PowerShell和我希望我能得到一些帮助创建一个脚本,告诉我一个文件的修改日期。我希望我能知道更多关于PowerShell的,因为我觉得我问了很多(我所有的空闲时间,本周将专门学习PS更好)。任何帮助将大大AP preciated。指点我在哪里可以学习如何做到这将是非常有益和方向。

下面是完整的破败。我需要运行报告每天,检查在90种不同的商店的计算机列表,以确保他们进行一定的备份。修改日期应该告诉如果已经执行备份,并且将设置为previous日期。如果修改后的日期是昨天,则并不需要是一个输出。如果不是昨天,我想在PowerShell窗口输出,或到一个文本文件,两者会更容易些。

我也有检查的文件夹不超过7天的每个90店,为输出同样的标准。
我有这个想法会是这样每个商店
对于存储1
检查文件日期为\\服务器\\店\\计算机\\ C:\\文件夹\\文件夹中最新的修改日期
如果日期等于昨天
   然后什么也不做
如果日期不等于昨天
   然后再输出测试中没有备份

支票夹修改日期为\\服务器\\样本\\店\\ backupfolder
如果日期等于7;天
   然后做nothign
如果日期等于> 7天前
   然后再输出的测试没有备份

编辑:对不起,不证明我的研究工作,我很新的PowerShell和我是在最后期限前完成这件事。我已经,从昨天起,学会了如何做到这一点,我需要这个脚本做的一切。感谢@Keith设置我正确的道路上。最后我用下面的code来完成我的唯一,扑灭位置,结果是假目标。

  $ a = GET-ChildItem \\\\服务器\\ XXX \\ Received_Orders \\ *。* |其中{$ _。LastWriteTime -ge(GET-日).AddDays(-7)}
如果($ A =(GET-ChildItem \\\\服务器\\ XXX \\ Received_Orders \\ *。* |其中{$ _。LastWriteTime -ge(GET-日).AddDays(-7)}))
{}
其他
{
STORE XXX没有收到任何订单在过去7天
}
$ B = GET-ChildItem \\\\ COMP名称\\文件夹\\ *。* |其中{$ _。LastWriteTime -ge(GET-日).AddDays(-1)}
如果($ B =(GET-ChildItem \\\\ COMP名\\ TFolder \\ *。* |其中{$ _。LastWriteTime -ge(GET-日).AddDays(-1)}))
{}
其他
{
STORE XXX没有运行其备份昨晚
}


解决方案

如果您运行Get-项目或Get-ChildItem命令这些将输出的System.IO.FileInfo 和<一个href=\"http://msdn.microsoft.com/en-us/library/system.io.directoryinfo.aspx\">System.IO.DirectoryInfo包含这些信息例如对象:

  GET-项目C:\\文件夹|格式列表

或者你也可以直接访问属性,像这样:

  GET-项目C:\\文件夹|的foreach {$ _。LastWriteTime}

要开始过滤的文件夹和放大器;基于上次写入时间的文件,你可以这样做:

  GET-ChildItem C:\\文件夹|其中{$ _。LastWriteTime -gt(GET-日).AddDays(-7)}

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. 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 PS better). Any help would be greatly appreciated. Pointing me in the direction of where to learn how to do this would be very helpful as well.

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. 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.

I also have to check that a folder is no older than 7 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 For 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"

EDIT: 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'
}

解决方案

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

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

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