Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 如何列出从昨天下午5点开始创建的文件?_Powershell - Fatal编程技术网

Powershell 如何列出从昨天下午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

无法使此命令正常工作。我正在尝试查看从昨天下午5点开始创建的名称中包含特定字符串的所有文件,无论我今天何时运行脚本。以下是我到目前为止的情况。任何帮助都将不胜感激

$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