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