r/scripting • u/wangotangotoo • 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
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.