0
votes

All,

I have a batch script that generates multiple log files in a single folder location. The log files are simply individual lines of text based on output from other applications. I was able to use the powershell cmdlet of "New-EventLog" to create a custom event log on my Windows 7 client machine. What I would like to do now is take the individual lines of text in each of the log files and loop through them one at a time, outputting each line to the event log as a separate entry. All I have been able to do at this point is send a single (but entire) log file to a single event log entry. Below is what I have:

@PowerShell -NoProfile -command "$OutText = Get-Content logfile.txt | Out-String;Write-EventLog -LogName CUSTOM -Source SCRIPT -EntryType Information -EventID 999 -Message $OutText

Note that I would like to be able to run this from within a batch script for simplicity sake but am open to other options.

Thank you.

1

1 Answers

0
votes

Try this:

Get-Content C:\Scripts\LogFile.txt | ForEach $_ {Write-EventLog -LogName CUSTOM -Source SCRIPT -EntryType Information -EventId 999 -Message $_

You can remove the $_ after ForEach if using v4 or higher PowerShell