0

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 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

1 Comment

You didn't need the $_ after ForEach in v3 either.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.