Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## show what plug'n'play devices are newly added by comparing devices present at two instances in time
- $devicesBefore = Get-CimInstance -ClassName Win32_PnPDevice
- ## wait for devices to change, eg insert a USB device, docking station, etc
- Get-CimInstance -ClassName Win32_PnPDevice | Where-Object { $with = $_ ; if( -Not $devicesBefore.Where( { $_.SystemElement.deviceid -ieq $with.SystemElement.deviceid } )) { $true } } | Select -ExpandProperty SystemElement | Select -ExpandProperty DeviceID | ForEach-Object { if( $_ -match '^([^\\]+)\\([^&]+)&([^\\&]+)' ) { [pscustomobject]@{ Type = $matches[1] ; Vendor = $matches[2] ; ProductId = $matches[3] ; Raw = $_ } } else { Write-Warning "Failed to parse $_" } } | sort Type,Vendor,ProductId -Unique
- ## For devices where a driver is available, there will be events 400 and 410 from provider Microsoft-Windows-Kernel-Pnp
- get-winevent -FilterHashtable @{ ProviderName = 'Microsoft-Windows-Kernel-Pnp' ; Id = 400 , 410 ; StartTime = ([Datetime]::Now.AddDays( -1.5 )) }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement