It also displays the three lines before and after every match from the cluster log file. The following command searches for lines with the word "err" preceded and followed by a space. Sometimes you may also want to know in which context the pattern appears.įor this purpose, Select-String has another interesting parameter named - Context, which shows you the lines before and after the string matching the pattern. Select-String -Path C:\Windows\WindowsUpdate.log -Pattern 'error','warning' Displaying only specific lines inside their context All patterns are processed with the logical OR operator.įor instance, the following command displays lines containing the word "error" or the word "warning" from the Windows Update agent log file. Select-String -Path C:\Windows\System32\LogFiles\Firewall\pfirewall.log ‑Pattern 'Drop' | Select-Object -Last 20įortunately, the - Pattern parameter accepts arrays as input, and you can provide several patterns to search. This searches all lines from the firewall log containing the word "Drop" and displays only the last 20 lines. If you want to search for packets the firewall has dropped, you can use the command below. In some cases, you may want to display only lines containing specific words. This means the cmdlet is waiting for new lines to display. There's a blinking underscore on that last screen. Get-Content -Path C:\Windows\WindowsUpdate.log -Tail 5 –Wait In the next example, the command line displays the last five lines of the WindowsUpdate.log and waits for additional lines to display. Please note that Get-Content still continues to wait for new lines even when the process or service writing to the file has already stopped. In this case, Get-Content continues to wait for new lines and displays them on the fly until you hit Ctrl+C. That's exactly the purpose of the - Wait parameter. Get-Content -Path C:\Windows\Logs\DISM\dism.log -Tail 50īecause some services write continuously to a log file, you may want to display new lines as soon as they appear. Thus, it's sometimes useful to view only the final lines of log files.įor instance, the following command displays the last 50 lines of the Deployment Image Servicing and Management (DISM) log file. However, usually the last lines are the most relevant ones because they contain either the global success messages or fatal errors. Get Content with paging output Displaying only the end of a log file
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |