powershell 分析文件夾內log查找匹配到的內容

 

 Get-ChildItem -Filter Application_Trace__*.log| ForEach-Object{ cat $_.FullName|where {$_ -match "返回錯誤代碼"}>>result.log}

或者 

ls -Filter Application_Trace__* |foreach {cat $_.FullName|?{$_ -match "錯誤"}>>result.log};

導出日誌

$DesPath = "F:\XXXX\XXX1201\"
#=================================================================================
$DaDate = Get-Date
$fd_Date=$DaDate.ToString('yyyy-MM-dd')
$LLogDate = $fd_Date.Replace("-","_") #日誌日期
 
$FileDate = $fd_Date.Replace("-","") #日誌日期
 
$printDate = $fd_Date
 
 
#當前路徑
$SrcPath =Split-Path -Parent $MyInvocation.MyCommand.Definition;
cd $SrcPath

$ExportPath="$SrcPath\Export_BOM_"+"$FileDate"
$bIsSrcExit = Test-Path($ExportPath)
if(-not $bIsSrcExit)
{
	mkdir $ExportPath
}
#【1】導出當前日期的數據庫db
cp $DesPath\ScData\*.db $ExportPath
#【2】導出當前日期的日誌
cp $DesPath\Log\*$LLogDate*.log $ExportPath
#【3】導出打印文件
$bIsDirExit = Test-Path("$ExportPath\PrintFile")
if(-not $bIsDirExit){
    mkdir "$ExportPath\PrintFile"
    cp $DesPath\ScData\PrintFile\$printDate\*.ptn $ExportPath\PrintFile\
}
#=================================================================================

$filezip = "Export_BOM_" +$FileDate + ".zip"

Compress-Archive -Update $ExportPath $filezip



rm -Force -Recurse $ExportPath

pause

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章