1
我有一個腳本,用於創建文本文件中列出的每日總使用量。 內每天統計文件的格式如下:Powershell,來自文本文件的總計
location,Feeder,total,endpoints
Oaklake,1,11153,310
oaklake,2,26214,291
oaklake,3,4593,147
oaklake,4,5279,145
這是我遇到的麻煩腳本的相關部分:
#create list of last month's days
if ((get-date).day -eq 2) {
$fullmonth = "location,Feeder,Usage,endpoints`n"
$year = (get-date).addmonths(-1).year
$month = (get-date).addmonths(-1).month
$days = 1..[datetime]::daysinmonth($year,$month) |
%{(get-date -day $_ -month $month -year $year).toshortdatestring()}
#select the file for each particular day and add it's content to $fullmonth
foreach ($day in $days) {
$dayfile = ls "c:\powershell\locationUse\summaries" |
?{$_.creationtime -gt $day -and $_.creationtime -lt $(get-date $day).adddays(1).toshortdatestring()} |
sort creationtime | select -last 1 | gc | select -skip 1
$fullmonth += $($dayfile | out-string)
}
$fullmonth | export-csv ./fullmonthtest.csv -notypeinformation
我的問題是fullmonthtest.csv的最終輸出是摘要 文件的最後一天的重複,例如:不正確地使用了「+ =」方法或東西我
location,Feeder,total,endpoints
Oaklake,1,11153,310
oaklake,2,26214,291
oaklake,3,4593,147
oaklake,4,5279,145
Oaklake,1,11153,310
oaklake,2,26214,291
oaklake,3,4593,147
oaklake,4,5279,145
Oaklake,1,11153,310
oaklake,2,26214,291
oaklake,3,4593,147
oaklake,4,5279,145
Oaklake,1,11153,310
oaklake,2,26214,291
oaklake,3,4593,147
oaklake,4,5279,145
是誰?感謝您的任何幫助,您可以提供!
刪除日期比較子句中的'.toshortdatestring()'調用 - 它肯定會搞砸比較,你可能最終會選擇最新的文件:)換句話說=不要比較蘋果和橙子:) –
我剛剛嘗試過,仍然是不正確的結果。 .creationtime是否與.toshortdatestring()或日期時間對象進行比較似乎並不重要。 – JayCee