Thursday, March 15, 2012

Using PowerShell to retreive CHKDSK log (Windows 7)

To easily check the latest CHKDSK log, enter this command into Windows PowerShell:

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


3 comments:

  1. This is exactly what I was looking for... thanks!

    ReplyDelete
  2. I wanted to save the results to a text file so I stumbled across changing your script to:

    Get-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)

    ReplyDelete
    Replies
    1. Try changing Desktop\chkdskresults.txt to:
      $env:UserProfile/Desktop/chkdskresults.txt

      Delete