ログとxmlファイルの整理とリネーム1
差分
このページの2つのバージョン間の差分を表示します。
次のリビジョン | 前のリビジョン | ||
ログとxmlファイルの整理とリネーム1 [2023/04/05 06:41] – 作成 taatin | ログとxmlファイルの整理とリネーム1 [2023/04/05 16:28] (現在) – 削除 taatin | ||
---|---|---|---|
行 1: | 行 1: | ||
- | # .logファイルを取得する | ||
- | $LogFiles = Get-ChildItem -Filter *.log | ||
- | |||
- | # 各.logファイルに対して処理を行う | ||
- | foreach ($LogFile in $LogFiles) { | ||
- | # ファイルの内容を取得する | ||
- | $FileContent = Get-Content $LogFile.FullName | ||
- | # ホスト名を抽出する | ||
- | $Hostname = ($FileContent | Select-String -Pattern "set hostname (.*)" | ||
- | # 日付部分を抽出する | ||
- | $Date = $LogFile.Name.Substring(0, | ||
- | |||
- | # 出力ファイル名を作成する | ||
- | $OutputFileName = " | ||
- | # 最後のコンフィグの開始行を見つける | ||
- | $ConfigStart = ($FileContent | Select-String -Pattern " | ||
- | # コンフィグの終了行を見つける | ||
- | $ConfigEnd = ($FileContent[$ConfigStart..($FileContent.Count - 1)] | Select-String -Pattern " | ||
- | # 開始行と終了行の間のテキストを抽出し、出力ファイル名で保存する | ||
- | $FileContent[$ConfigStart-1..($ConfigStart + $ConfigEnd-1)] | Set-Content $OutputFileName | ||
- | |||
- | # XMLファイルの処理 | ||
- | $XmlFile = Get-ChildItem -Filter *.xml | Where-Object { (([xml](Get-Content $_.FullName)).SelectSingleNode("// | ||
- | $XmlOutputFileName = " | ||
- | # XMLファイル名を変更する | ||
- | Rename-Item $XmlFile.FullName $XmlOutputFileName | ||
- | |||
- | # yyyymmddのフォルダを作成し、ファイルをコピーする | ||
- | $OutputFolder = New-Item -ItemType Directory -Force -Path $Date | ||
- | Copy-Item $OutputFileName -Destination $OutputFolder.FullName | ||
- | Copy-Item $XmlOutputFileName -Destination $OutputFolder.FullName | ||
- | } | ||
ログとxmlファイルの整理とリネーム1.1680676860.txt.gz · 最終更新: 2023/04/05 06:41 by taatin