![]() $strData = Get-WinEvent -LogName "Windows PowerShell" # Get events in the Windows PowerShell event log Here is the PowerShell script that selects the last line of a string. ![]() The Select-Object command uses the Last parameter to select the last line from a string. Then, the $strData output is piped to the Select-Object cmdlet. The Get-WinEvent cmdlet uses the LogName parameter to get all events in the Windows PowerShell log and save the output in the $strData variable. The Select-Object command has a Last parameter that selects the last lines of string based on the number of lines specified. To get the last line of the string stored in a variable, use the Select-Object cmdlet in PowerShell. Using the pipe operator, it passed extracted lines to Out-File export to a csv file.Ĭool Tip: Use PowerShell to get the first line of the file! Get the Last Line of the String In the above script, the PowerShell Get-Content cmdlet -tail parameter gets the last 50 lines of the code. To get the tail of the last 50 lines of a big file and export it csv file, use the below command Get-Content "C:\PowerShell\EventLog_Setup.txt" -tail 50 | Out-File -FilePath "C:\PowerShell\output.csv" Often administrators need to extract a few lines from the big log file to analyze the log data. Get-Content "C:\PowerShell\EventLog_Setup.txt" -tail 1Ĭool Tip: Do you know the equivalent of the cat command in Windows! Get the tail of the big file and export it to csv ![]() In the following PowerShell script, the Get-Content command uses the -tail 1 parameter to get the last line of the text file specified. To get the last line of the file, use the tail parameter with the value 1. PowerShell tail – Show the last line of the file The output of the above PowerShell script uses the Get-Content command to get the last 10 lines of the file. Get-Content -Path D:\PS\event_log.txt -Tail 10 This command uses the tail parameter to specify the number of lines to retrieve from the text file. To get the last 10 lines of the Windows Event log text file, use the Get-Content command that uses the Path Parameter to specify the event log text file path. Let’s understand using Get-Content tail examples to read the end of the file, A file can be iis log file, Windows event log, firewall log, or any other file.Ĭool Tip: How to get certificates using PowerShell! PowerShell tail – Get the Last 10 Lines of the File
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |