标题: [转载代码] [PowerShell每日技巧]监控日志文件(20131115) [打印本页]
作者: DAIC 时间: 2013-11-18 09:04 标题: [PowerShell每日技巧]监控日志文件(20131115)
Beginning in PowerShell 3.0, it is easy to monitor text-based log files in real-time. Try this:- $Path = "$home\Desktop\testfile.txt"
-
- 'Test' | Out-File "$home\Desktop\testfile.txt"
- notepad $Path
-
- Get-Content -Path $Path -Tail 0 -Wait | Out-GridView -Title $Path
复制代码
This will create a test file on your desktop, and then open the file in the Notepad. PowerShell will then start monitoring the file. Once you type new text into the Notepad window and save it, the changes will appear in a PowerShell grid view.
Simply replace the path with any text-based log file you'd like to keep an eye on. Since PowerShell is blocked while it is monitoring the file, you may want to execute the code in a separate PowerShell instance.
http://powershell.com/cs/blogs/tips/archive/2013/11/15/monitoring-log-files.aspx
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |