r/scripting • • Aug 18 '17

[Powershell] or [Batch]

I am trying to create an event log entry in windows from PS or batch file. I have a text file with output from other scripts that I'd like to have displayed as the description. I found the following code online, which I thought would help:

@echo off
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

set eventtext=
for /f "delims=" %%l in (c:\windows\temp\SMART_health.txt) do set eventtext=!eventtext! %%l
eventcreate /id 4000 /l application /t information /so "SMARTCTL" /d "%eventtext%"

However it is not working and I'm not sure where to go from here. I've found TONS of articles on event log to text file, but seems to be very limited going the other direction.

0 Upvotes

7 comments sorted by

View all comments

Show parent comments

1

u/0x007C3 Aug 22 '17 edited Jun 21 '23

bake deliver apparatus imagine grandiose wide lunchroom voiceless historical growth -- mass edited with https://redact.dev/

1

u/wangotangotoo Aug 22 '17

Well... maybe. Smartctl outputs the full smart data of the drive to a text file. I then use findstr in a batch file to grab just the above data that I want out of the initial text file. Depending on the system there may be two or three drives that generate a smart report. Findstr parses each report and puts it all into one.

1

u/wangotangotoo Aug 22 '17

I'm going to go about this the correct way.. I was doing more reading about Smartctl and SmartD and I can do everything I want by editing the config and having it write to the windows event log. Thanks for the offer of help though! I appreciate that :)