Device drivers’ events on Windows 8

As you can see in the following screenshots, there’s a new tab in the device manager that shows events related to this device.
new device manager events tab
If you click the “View All Events”, the custom view is created on the fly in the event viewer.
eventlog custom view
With powershell 3 we can achieve the same view and even better we can gather these filtered events as objects.
We can easily add query against remote computers but we can not specify credentials as the Get-EventLog hasn’t currently a credentials parameter.

# Requires -version 3.0

Function Get-DeviceEvents


        [system.string[]]$HardwareID = $null
    Begin {
        $paramHT = @{
            ErrorAction = 'Stop'
    Process {
        $Computername | ForEach-Object -Process {
            $Computer = $_
            If ($Computer -ne $Env:Computername)            
                $paramHT += @{Computername = $Computer}            

            $HardwareID | ForEach-Object -Process {
                $devid = $_
                # Replace ampersand
                $hwid = $devid -replace "&","&"

                # Create the XML query
                $query = @"
                  <Query Id="0" Path="Microsoft-Windows-Kernel-PnP/Configuration">
                    <Select Path="Microsoft-Windows-Kernel-PnP/Configuration">
                     and EventData/Data
                    <Select Path="System">
                    and UserData/*/DeviceInstanceID='$hwid']
                    Get-WinEvent -FilterXml $query @paramHT | ForEach-Object -Process {
                        Get-EventLog -InstanceId $($_.Id) -LogName $($_.LogName) -AsBaseObject -Index ($_.RecordID) @paramHT
                } catch {
                    Write-Warning -Message "Failed to query events against computer $Computer for DeviceID $devid $($_.Exception.Message)"
    End {}
} # end of function


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your 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.