PowerTip: Use PowerShell to Troubleshoot PowerShell

Summary: Use Windows PowerShell to troubleshoot errors with Windows PowerShell.

Hey, Scripting Guy! Question How can I use Windows PowerShell to troubleshoot issues with Windows PowerShell?

Hey, Scripting Guy! Answer Use the Get-WinEvent cmdlet to parse the Windows PowerShell log. For example, to find all errors in a Windows PowerShell log:

In Windows PowerShell 3.0:

Get-WinEvent -LogName *powershell* | where leveldisplayname -eq ‘error’

In Windows PowerShell 2.0:

Get-WinEvent -LogName *powershell* | where {$_.LevelDisplayName -eq ‘error’}

You can also group by the error ID to get an idea of how often a particular error appears:

In Windows PowerShell 3.0:

Get-WinEvent -LogName *powershell* | where leveldisplayname -eq ‘error’ | group id

In Windows PowerShell 2.0:

Get-WinEvent -LogName *powershell* | where {$_.LevelDisplayName -eq ‘error’} | group id