![](/img/trans.png)
[英]in PowerShell how do I Loop through CSV file and create a summary hashtable based on key value in csv
[英]Powershell Contiguous Date summary
從這個 object (和其他類似的):
$Times = @(
"12:00 AM",
"1:00 AM",
"2:00 AM",
"3:00 AM",
"4:00 AM",
"5:00 AM",
"6:00 AM",
"7:00 AM",
"8:00 AM",
"9:00 AM",
"10:00 AM",
"11:00 AM",
"12:00 PM",
"1:00 PM",
"2:00 PM",
"3:00 PM",
"4:00 PM",
"5:00 PM",
"6:00 PM",
"7:00 PM",
"8:00 PM",
"9:00 PM",
"10:00 PM",
"11:00 PM"
)
$Example = @()
$times | % {$time = $_; $Example += [pscustomobject]@{Day = 'Sunday'; Time = $time;RatelimitingSchedule = '100'}}
$Example[5].RatelimitingSchedule = '50'
6..20 | % {$Example[$_].RatelimitingSchedule = '10'}
$Example[21].RatelimitingSchedule = '50'
$Example
這會產生 output 像這樣:在此處輸入圖像描述
我的問題是,我怎樣才能將它按摩成這個匯總表格(按所示順序):
歡迎任何幫助!
對於任何在未來尋找這個答案的人...... https://www.reddit.com/user/bis/請為我創建這個:
&{ $Example; 0 } | # append a dummy to the end of the data, so the last record gets processed
ForEach-Object -Begin {
$StartTime = $EndTime = $null
$CurrentRate = -1
} -Process {
if($_.RateLimitingSchedule -eq $CurrentRate) {
$EndTime = $_.Time
} else {
if($null -ne $StartTime) {
[pscustomobject]@{Start = $StartTime; End = $EnDTime; Rate =
$CurrentRate}
}
$StartTime = $EndTime = $_.Time
$CurrentRate = $_.RateLimitingSchedule
}
} |
ForEach-Object {
"between $($_.Start) and $($_.End), $($_.Rate)% Rate limiting"
}
作為這篇文章的一部分: https://www.reddit.com/r/PowerShell/comments/wpuxm2/24hour_contiguous_schedule_summary/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.