I have create a little script to run and print out whenever I have a driver installed, The problem I am having is when I call Compare-Object
the script seems to hang and only run this code on quit.
I have already tried | out-null
and waitjob
with no avail
$global:drivers = $null
function checkDrivers{
$temp = Driverquery.exe /V
# testing
$temp += "newDriver SMS Process Event Driv SMS Process Event Driv Kernel Manual Running OK TRUE FALSE 8,192 8,192 0 03/08/2011 8:56:26 AM C:\WINDOWS\system32\DRIVERS\prepdrv.sys 4,096"
if($temp.Length -eq $global:drivers.Length){
return
}
Write-Output "[---] Driver Installed"
Compare-Object -ReferenceObject $global:drivers -DifferenceObject $temp
$global:drivers = $temp
}
Write-Output "[+] Parsing initial drivers..."
$global:drivers = Driverquery.exe /V
Write-Output "[+] Parsing complete`n"
Write-Output "[+] Press 'q' to quit"
Write-Output "[+] Scanning for Driver Installs..."
while ($true){
if ($Host.UI.RawUI.KeyAvailable -and ("q" -eq $Host.UI.RawUI.ReadKey("IncludeKeyUp,NoEcho").Character)) {
Write-Host "Exiting now..." -Background DarkRed
break;
}
checkDrivers
start-sleep -seconds 5
}
Here is my output, I expected the Object compare line to be executed before quit under [---] Driver Installed
[+] Parsing initial drivers...
[+] Parsing complete
[+] Press 'q' to quit
[+] Scanning for Driver Installs...
[---] Driver Installed
Exiting now...
InputObject SideIndicator
----------- -------------
newDriver SMS Process Event Driv SMS Process Event Driv Kernel Manual Running OK TRUE FALSE 8,192 8,192 0 03/08/2011 8:56:26 AM C:\WINDOWS\system32\DRIVERS\prepdrv.sys 4,096 =>