我已經寫了一個PowerShell來查找日誌文件中的模式,然後將它們重定向到日誌文件。 我想爲每個服務器設置標頭,因此編寫如下代碼:寫主機輸出沒有被重定向到日誌文件
但是頭文件沒有重定向到日誌文件。 請任何建議。
代碼如下所述:
$date_value=Get-Date -Format ddMMM
#$file_path="D:\Temp\Arun\mu.log"
$file_path1="\\server1\d$\Temp\Arun\abc.log"
$file_path2="\\server2\d$\Temp\Arun\abc.log"
$file_path3="\\server3\d$\Temp\Arun\abc.log"
# Set the match patterns in the three clusters
$match_pattern1=select-string -pattern $date_value $file_path1
$match_pattern2=select-string -pattern $date_value $file_path2
$match_pattern3=select-string -pattern $date_value $file_path3
$LogDir="D:\temp\arun\Log\"
$DTS=Get-Date -Format "yyyy_MM_dd_HH_mm_ss"
$LogFile = $LogDir+"fetch_data."+$DTS+".log"
$OldLog = $LogFile+".old"
Write-Host "**********************************************************" >> $LogFile
Write-Host "Checking log for today's entries in SERVER1" >> $LogFile
Write-Host "**********************************************************" >> $LogFile
$match_pattern1 >> $LogFile
Write-Host "**********************************************************" >> $LogFile
Write-Host "Checking log for today's entries in SERVER2" >> $LogFile
Write-Host "**********************************************************" >> $LogFile
$match_pattern2 >> $LogFile
Write-Host "**********************************************************" >> $LogFile
Write-Host "Checking log for today's entries in SERVER3" >> $LogFile
Write-Host "**********************************************************" >> $LogFile
$match_pattern3 >> $LogFile
我也希望如果有人能幫助我在得到另外一個代碼的上方,作爲電子郵件的附件該日誌文件。
只是將其刪除!或者使用'write-output'代替。 –
您是否考慮過使用[Start-Transcript](http://ss64.com/ps/start-transcript.html)/ [Stop-Transcript](http:// ss64 .com/ps/stop-transcript.html)cmdlet取而代之? –