按文件创建日期范围限制 Powershell Get-ChildItem [英] Limiting Powershell Get-ChildItem by File Creation Date Range

查看:37
本文介绍了按文件创建日期范围限制 Powershell Get-ChildItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Powershell 命令生成某些文件类型的 CSV 报告.我的目标是找出在特定日期范围内添加了多少.现在,脚本会找到所有内容,我按日期排序以找到我的号码.我想修改命令以仅返回创建日期范围内的对象,即如果此文件是在 2013 年 3 月 1 日至 2013 年 3 月 31 日之间创建的.可能有一种方法可以通过日期范围来限制命令,可能使用 Select-对象,我就是想不通.

I use a Powershell command to generate a CSV report of certain file types. My goal is to find out how many were added during a particular date range. Right now, the script finds everything and I sort by date to find my number. I'd like to modify the command to only return objects within a creation date rage, i.e. if this file was created between 1 March 2013 and 31 March 2013. There's probably a way to limit the command by a date range, likely using Select-Object, I just can't figure it out.

Get-ChildItem 'PATH' -recurse -include @("*.tif*","*.jp2","*.pdf") | Select-Object FullName, CreationTime, @{Name="Mbytes";Expression={$_.Length/1Kb}}, @{Name="Age";Expression={(((Get-Date) - $_.CreationTime).Days)}} | Export-Csv 'PATH\scans.csv'

推荐答案

使用Where-Object并测试$_.CreationTime:

Get-ChildItem 'PATH' -recurse -include @("*.tif*","*.jp2","*.pdf") | 
    Where-Object { $_.CreationTime -ge "03/01/2013" -and $_.CreationTime -le "03/31/2013" }

这篇关于按文件创建日期范围限制 Powershell Get-ChildItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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