Powershell to Output Recent Issues

 

Whilst working on my chat bot I got to thinking about how it would be great if an end user could run a simple script to gather basic information about their computer and came up with the below. It’s a script that captures the computers name, model, serial number, RAM, 25 recent errors from the Application and System Logs and finally it notes any application hangs before dumping all the information into a text file (to easily be given to tech support). I was also considering recording IP address, MAC address and possibly recently installed Windows Updates (all possible via PowerShell).

#Powershell script to gather computer basics

$text = “What’s wrong with my PC?”

#This is where the file is saved

$reportname = “C:\Temp\report.txt”

 

$text | out-file $reportname

 

#This outputs the basic computer information

Get-WmiObject -Class Win32_ComputerSystem | out-file $reportname -append

 

#This outputs the last 25 system log errors

$syslogoutput = “System Log Errors”

$syslogoutput | out-file $reportname -append

Get-EventLog -LogName System -EntryType Error -Newest 25 | out-file $reportname -append

 

#This outputs the last 25 application log errors

$applogoutput = “App Log Errors”

$applogoutput | out-file $reportname -append

Get-EventLog -LogName Application -EntryType Error -Newest 25 | out-file $reportname -append

 

#This ouputs any application hang events

$apphangoutput = “Application Hang Events”

$apphangoutput | out-file $reportname -append

Get-WmiObject Win32_ReliabilityRecords -Filter “SourceName=’Application Hang'” | out-file $reportname -append

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.