2016-02-12 22 views
0

无法使此命令正常工作。我试图在昨天下午5点以后创建的名称中看到所有具有特定字符串的文件,无论我今天什么时候运行脚本。以下是我到目前为止。任何帮助将不胜感激。如何列出昨天下午5:00以来创建的文件?

$today = (get-date).dayofyear 
$string = "blah" 
$filepath = "C:\files" 

Get-ChildItem -Recurse -Force $filePath | where { $_.CreationTime.dayofyear -eq (($today)-1) } -and { $_.CreationTime.hour -ge 17 | Where-Object { ($_.PSIsContainer -eq $false) -and ($_.Name -like "*$string*"} 

回答

0

得到公正的DateTime值(它给你今天在0:00:00)的Date部分,并从减去7小时至昨日下午5时得到的。

$cutoff = (Get-Date).Date.AddHours(-7) 

Get-ChildItem -Recurse -Force $filePath | Where-Object { 
    -not $_.PSIsContainer -and 
    $_.CreationTime -ge $cutoff -and 
    $_.Name -like "*$string*" 
} 

如果您有PowerShell的V3或更高版本,你可以通过调用Get-ChildItem与参数-File更换条件-not $_.PSIsContainer

+0

这很好。非常感谢。 –

相关问题