ワンライナーで書くとこんな感じ。
=======================
$time = 0..23 | % {$_.ToString("00")} ; foreach ($i in $time){Get-Content ".\LogFile.txt" | select -First 1 | Out-File ".\LogFile_$i.txt"; Get-Content ".\LogFile.txt" | ? {$_ -match "^2019-10-15 $i"} | Out-File ".\LogFile_$i.txt" -Append}
=======================
少し読み取りやすく直してみます
=======================
$time = 0..23 | % {$_.ToString("00")} # "00"から"23"の文字列の配列を作成
foreach ($i in $time){ # $i変数を00から23で繰り返し実行
Get-Content ".\LogFile.txt" |
Select-Object -First 1 | # ヘッダー行を取得
Out-File ".\LogFile_$i.txt" # LogFile_HH.txtファイルにヘッダーを書き込み
Get-Content ".\LogFile.txt" |
Where-Object {$_ -match "^2019-10-15 $i"} | # 特定時間の行を取得
Out-File ".\LogFile_$i.txt" -Append # LogFile_HHファイルに書き込み
}
=======================