解析しようとしているログ ファイルがありますが、解決策を見つけることができませんでした。以下のログ ファイルの一部をコピーしました。3 行の各グループが 1 つのエラーです。
csrak17 remove int_rpsmkt
Could not perform the administration request
Error: HPDMG1064E The group member was not found. (status 0x14c01428)
csrak17 add int_rpsops
Could not perform the administration request
Error: HPDMG1064E The group member was not found. (status 0x14c01428)
csrak17 remove int_rpssales
Could not perform the administration request
Error: HPDMG1064E The group member was not found. (status 0x14c01428)
csrak17 remove int_tpd
Could not perform the administration request
Error: HPDMG1064E The group member was not found. (status 0x14c01428)
csrak17 remove int_trpit
Could not perform the administration request
Error: HPDMG1064E The group member was not found. (status 0x14c01428)
ログ ファイルを配列に読み込んでいますが、問題なくエラー コードを含む行が返されます。まず、「エラー: HPDMG1064E」の行を見つけてから、2 行前に戻って「add」という単語が含まれているかどうかを確認します (2 番目のグループの例のように)。
別の配列で見つかった値に基づいて配列内の行を返す方法はありますか? もちろん、ファイルをループしてプロセスを繰り返します。
これが私がこれまでに持っているものですが、何らかの理由で出力ファイルに1行しか返されません。また、ご覧のとおり、現在のインデックスに基づいて別のインデックスを見つけようとするコードはありません。
$logs = Get-Content C:\Temp\test\ProdtamResults_HPDMG1064E_errors.doc
$Value = "HPDMG1064E"
foreach($log in $logs) {
$i = 0
while ($i -le $logs.length-1) {
if ($logs[$i] -match $Value)
{
return $logs[$i] | out-file C:\Temp\test\results.txt
}
$i++
}
}