只需在當前月份的第一天和當月的最後一天之間選擇文件夾中的文件。我想:Powershell在日期之間獲取文件
$curr_month = (get-date -format "MM/01/yyyy 0:00:00")
$next_month = (get-date $curr_moth).addmonths(1)
Get-ChildItem "\\logserver\C$\WINDOWS\SYSTEM32\LOGFILES\" -Recurse -include @("*.log") |
where {$_.CreationTime -ge $curr_month -and
$_.CreationTime -lt $next_month
}
我只得到第一個日誌文件,並繼續錯誤:
Get-ChildItem : The specified network name is no longer available.
At line:3 char:18
+ Get-ChildItem <<<< "\\logserver\C$\WINDOWS\SYSTEM32\LOGFILES\" -Recurse -include @("*.log") |
+ CategoryInfo : ReadError: (\\logserver\C$\WI...ES\WMI\RtBackup:String) [Get-ChildItem], IOException
+ FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand
問題二:只能從路的第一級(不深遞歸)。
有對可能的解決方案,但想知道,有什麼不好與第一代碼... $ curr_month =(獲得最新-format 「MM-01-YYYY 0:00:00」) $ next_month =( get-date $ curr_moth).addmonths(1) ls \\ logserver \ C $ \ WINDOWS \ SYSTEM32 \ LOGFILES \ *。log |其中{$ _。CreationTime -ge $ curr_month-和$ _。CreationTime -lt $ next_month} – Jerry1
不應該是$ _。where子句中的CreationTime.Month嗎? –
變量的名字'curr_month'有點令人困惑,但正如你從第一行看到的那樣,si格式爲MM/dd/yyyy(dd = 01),所以where子句是好的。奇怪的是,錯誤... – Jerry1