| 
| 
| 
| #212750 - 2017-10-17 10:58 AM  Read Information from Eventlog |  
| stefanhfli   Fresh Scripter
 
 Registered:  2015-01-29
 Posts: 7
 Loc:  Germany
 | 
Hello,
 how can i read the information "BootTime", "MainPathBootTime", "BootPostBootTime" from the latest eventlog (Microsoft-Windows-Diagnostics-Performance/Operational) eventid 100 and write it into a txt file.
 
 Sorry for my englisch :-)
 
 Edited by stefanhfli (2017-10-17 11:25 AM)
 
 |  
| Top |  |  |  |  
| 
| 
| #212752 - 2017-10-17 12:47 PM  Re: Read Information from Eventlog
[Re:  Jochen] |  
| stefanhfli   Fresh Scripter
 
 Registered:  2015-01-29
 Posts: 7
 Loc:  Germany
 | 
I used these 2 Options with an example syntax: 
 $array = ReadEventlog('Security',4732)
 $abs=WriteFile('c:\KIX\file.txt',$array)
 
 For this example i get an output in the file.txt.
 
 When i use the following syntax i donīt get an output and i donīt no why:
 
 $array = ReadEventlog('Microsoft-Windows-Diagnostics-Performance/Operational',100)
 $abs=WriteFile('c:\KIX\file.txt',$array)
 
 |  
| Top |  |  |  |  
| 
| 
| #212756 - 2017-10-17 01:05 PM  Re: Read Information from Eventlog
[Re:  Jochen] |  
| stefanhfli   Fresh Scripter
 
 Registered:  2015-01-29
 Posts: 7
 Loc:  Germany
 | 
Ok thanks for your help.
 I think that is too complicated for me.
 
 |  
| Top |  |  |  |  
| 
| 
| #212757 - 2017-10-17 01:26 PM  Re: Read Information from Eventlog
[Re:  stefanhfli] |  
| stefanhfli   Fresh Scripter
 
 Registered:  2015-01-29
 Posts: 7
 Loc:  Germany
 | 
Is there no other way to get the 3 Informations?
 |  
| Top |  |  |  |  
| 
| 
| #212762 - 2017-10-17 04:19 PM  Re: Read Information from Eventlog
[Re:  Jochen] |  
| Jochen   KiX Supporter
 
       
   Registered:  2000-03-17
 Posts: 6380
 Loc:  Stuttgart, Germany
 | 
Ok, found something .. Win32_NTLogEvent class is not capable by default to read the new set of "Application and Services" logs introduced with Win7/Server 2008.
 There is a workaround creating a registry key (for each logfile its own)
  (provided the user running the script has sufficient access) 
 In your case it is HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Microsoft-Windows-Diagnostics-Performance/Operational
 
 Which is, to say the least, kinda annoying.
 
 Furthermore I only managed by now to get a direct request to ReadEventlog() to work for me. Like ReadEventlog("Microsoft-Windows-Diagnostics-Performance/Operational", 100) which is a pain to sort out as it returns a metric ton of data
  
 A WQL Query like this (tried of course other, simpler combinations) returns only empty strings
   
 
 
if not keyexist("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Microsoft-Windows-Diagnostics-Performance/Operational")
    $ = addkey("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Microsoft-Windows-Diagnostics-Performance/Operational")
    @error ??
endif
$events = ReadEventlog('SELECT InsertionStrings FROM Win32_NTLogEvent
                        WHERE Logfile="Microsoft-Windows-Diagnostics-Performance/Operational" AND EventCode=100')
if ubound($events,1) > -1
    "BootTime: " + split($events[0,0],@crlf)[5] ?
    "MainPathBootTime: " + split($events[0,0],@crlf)[6]   ?
    "BootPostBootTime: " + split($events[0,0],@crlf)[19]   ?
endif
get $
 
 [Edit]
 the above query is of course nonsense. A quick peek at the class in wbemtest uncovers this.
 Still, using the correct statements like TimeGenerated and Message returns nothing[/Edit]
 
 [Edit2]
 Meh, InsertionStrings holds the information we're looking for. Edited code above is working now. Please Note that it will return only the latest event. Of course $events hold all available events but events[0,0] is the latest
 [/Edit2]
 
 
 
 Edited by Jochen (2017-10-18 09:47 AM)
 
_________________________   |  
| Top |  |  |  |  
| 
| 
| #212764 - 2017-10-17 05:10 PM  Re: Read Information from Eventlog
[Re:  Jochen] |  
| Jochen   KiX Supporter
 
       
   Registered:  2000-03-17
 Posts: 6380
 Loc:  Stuttgart, Germany
 | 
Allright allright,
 in the end just splitting the correct array element by crlf peeking the correct positions and bam:
 
 
 
break on
$= setoption("WrapatEOL","ON")
if not keyexist("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Microsoft-Windows-Diagnostics-Performance/Operational")
    $ = addkey("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Microsoft-Windows-Diagnostics-Performance/Operational")
    @error ??
endif
$events = ReadEventlog("Microsoft-Windows-Diagnostics-Performance/Operational", 100)
if ubound($events,1) > -1
    "BootTime: " + split($events[0,7],@crlf)[5] ?
    "MainPathBootTime: " + split($events[0,7],@crlf)[6]   ?
    "BootPostBootTime: " + split($events[0,7],@crlf)[19]   ?
endif
get $
 wonder if there is a more comfortable way using Powershell ... guess not!
 
_________________________   |  
| Top |  |  |  |  
| 
| 
| #212766 - 2017-10-18 09:38 AM  Re: Read Information from Eventlog
[Re:  Jochen] |  
| stefanhfli   Fresh Scripter
 
 Registered:  2015-01-29
 Posts: 7
 Loc:  Germany
 | 
Hello Jochen,
 thanks for your help, you are great.
 
 I have customized it for our environment and now i have what i want.
 
 Thanks !!!
 
 |  
| Top |  |  |  |  
| 
| 
| #212800 - 2017-11-01 12:26 PM  Re: Read Information from Eventlog
[Re:  Jochen] |  
| stefanhfli   Fresh Scripter
 
 Registered:  2015-01-29
 Posts: 7
 Loc:  Germany
 | 
Hello Jochen,
 I need your help again.
 
 When i try to get the BootStartTime from the eventlog with
 "BootStartTime: " + split($events[0,7],@crlf)[1] ?
 i get an empty string.
 
 |  
| Top |  |  |  |  
 Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
 
 | 
| 
 
| 0 registered
and 324 anonymous users online. 
 | 
 |  |