Powershell 如何列出从昨天下午5点开始创建的文件?
无法使此命令正常工作。我正在尝试查看从昨天下午5点开始创建的名称中包含特定字符串的所有文件,无论我今天何时运行脚本。以下是我到目前为止的情况。任何帮助都将不胜感激Powershell 如何列出从昨天下午5点开始创建的文件?,powershell,Powershell,无法使此命令正常工作。我正在尝试查看从昨天下午5点开始创建的名称中包含特定字符串的所有文件,无论我今天何时运行脚本。以下是我到目前为止的情况。任何帮助都将不胜感激 $today = (get-date).dayofyear $string = "blah" $filepath = "C:\files" Get-ChildItem -Recurse -Force $filePath | where { $_.CreationTime.dayofyear -eq (($today)-1) } -a
$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*"}
仅获取
DateTime
值的Date
部分(该值为今天的0:00:00),然后从中减去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或更高版本,则可以通过使用参数-File
调用Get ChildItem
来替换条件-not$.psicContainer