Get-EventLog -LogName Application -Source wininit | Select-Object -Last 1 -ExpandProperty message
This command will query the Application log with any entry whose source is "wininit" and then those objects are piped to select and expand only the "Message" property of the most recent entry.
Please note that the command above is a "one-liner" (no line break).
NOTE: I have only tried this on Windows 7 OS
This is exactly what I was looking for... thanks!
ReplyDeleteI wanted to save the results to a text file so I stumbled across changing your script to:
ReplyDeleteGet-EventLog -LogName Application -Source wininit | Select-Object -Last 1 -ExpandProperty message | out-file Desktop\chkdskresults.txt
It works fine in the Powershell environment but not when I save it as a .ps1 file and try to run it. Can you tell me how to make this a script that can be run? (I want to run it from Task Scheduler)
Try changing Desktop\chkdskresults.txt to:
Delete$env:UserProfile/Desktop/chkdskresults.txt