powershell - 基于小时和分钟的Powershell搜索文件?
问题描述
我有一个 powershell 脚本选择在特定时间之间创建的文件,如下所示
if ($a.CreationTime -gt (get-date).date -and
$a.CreationTime.Hour -ge 14 -and
$a.CreationTime.Hour -le 15){...}
这将从当天以及 和 之间拾取2PM
文件3PM
。
现在我想将时间范围更改为介于1:30 PM
和之间3:30 PM
,如何处理脚本中的分钟数?
解决方案
这是一口但你不能使用:
Get-ChildItem | ForEach-Object{
switch ($_.CreationTime.Hour){
#creation hour is 1, check if minutes are over 30
1 { if ($_.CreationTime.Minute -ge 30){ Write-Host $_; break} }
#since hour is 2, no other check needed
2 { Write-Host $_; break}
#creation hour is 3, check if minutes is under 30
3 { if ($_.CreationTime.Minute-le 30){ Write-Host $_; break } }
#hour isn't 1,2 or 3 so do nothing
default {break}
}
}
推荐阅读
- nuxt.js - 如果传递了“上下文”,如何在 Nuxt 的 fetch() 钩子中访问“this”?
- flutter - 参数类型'列表
?不能分配给参数类型“列表” ' - ios - SwiftUI:macOS 应用程序的 fullScreenCover 等效项?
- python - 如何在没有索引的情况下将 Pandas 数据框打印到 Latex?
- r - 在 R 的一个方面用两个可能的选项重新排序 x 轴
- c++ - 未定义模板的隐式实例化:g++ 或 clang++
- javascript - 如何删除空数组javascript中的推送项目?
- react-native - 反应本机重新选择状态未定义
- r - 为在 R 中使用 grid.arrange() 创建的每一行图赋予一个标题
- ios - M1 mbp 使用 xcode 12.5.1 使用设备“我的 mac(为 iphone 设计)”进行调试,但“在调试器附加到它之前无法启动或退出”