PowerShell的 - 如何检查是否有需要的创建时间文件是否存在?(Powershell - H

2019-07-29 05:47发布

我使用这个脚本

$date = Get-Date
Get-Childitem -name | where {$_.CreationTime -eq "$date"}

但它不工作。 所有我需要的是做一个布尔检查是否有在特定日期创建的文件。 谢谢。

Answer 1:

Get-Date获取当前日期和时间。 如果你比较文件的创建日期与当前日期时间,你不会找到任何文件(除了您刚才已创建了一个在检索当前日期;))。

$today = (get-date).Date
Get-ChildItem | where { $_.CreationTime.Date -eq $today }


Answer 2:

Get-ChildItem | where-object { $_.CreationTime.Date -match "2014" }

其中, 2014是创造的一年。



文章来源: Powershell - How to check if file with desired creation time exists?