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
{
    [CmdletBinding()]
    param(

        [Parameter(ValueFromPipeline,ValueFromPipelineByPropertyName)]            
        [Alias("CN","__SERVER","IPAddress")]            
        [system.string[]]$ComputerName=$Env:Computername,

        [parameter()]            
        [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 = @"
                <QueryList>
                  <Query Id="0" Path="Microsoft-Windows-Kernel-PnP/Configuration">
                    <Select Path="Microsoft-Windows-Kernel-PnP/Configuration">
                    *[System/Provider[@Name='Microsoft-Windows-Kernel-PnP']
                     and EventData/Data
                     [@Name='DeviceInstanceID']='$hwid']
                     </Select>
                    <Select Path="System">
                    *[System/Provider[@Name='Microsoft-Windows-UserPnp']
                    and UserData/*/DeviceInstanceID='$hwid']
                    </Select>
                  </Query>
                </QueryList>
"@
                try
                {
                    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


Advertisements

Leave a Reply

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

WordPress.com Logo

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

Google+ photo

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

Connecting to %s