registry - How do I time out a REGQUERY command in Powershell? -


i trying find way (maybe job?) timeout system jobs. seems regquery time out after 42 seconds if computer not online, , code can't reach registry. looking limit query around 5 seconds have tonne of computers in our environment. have tried play around creating jobs, stopwatch, etc. no luck :( please help!

$file = import-csv 'c:\temp\regcomplist.txt' $results="" $text="machine name,regkey value, runtime" $fileout = "c:\temp\regquery.csv" write-host $text out-file -filepath $fileout -inputobject $text -force $timeout = new-timespan -seconds 5 $swtotal = [diagnostics.stopwatch]::startnew() foreach ($line in $file) { try{ $regkey = "" $keyvalue = "" $machinename = $line.machinename #trap [exception] {continue}     $key = "system\\currentcontrolset\\control\\print\\environments\\windows x64\\drivers\\version-3\\lexmark universal v2 xl" $sw = [diagnostics.stopwatch]::startnew()    #while ($sw.elapsed -lt $timeout){     $reg = [microsoft.win32.registrykey]::openremotebasekey("localmachine",$machinename)     $regkey = $reg.opensubkey($key)     $keyvalue = $regkey.getvalue('help file')  #   return #} #start-sleep -seconds 5 #if ($ok -ne "ok"){$keyvalue = "timed out: "+$sw.elapsed} } catch{ $keyvalue = "error opening registry" } $text = $machinename+","+$keyvalue+","+$sw.elapsed $results += $text #output below here: write-host $text out-file -inputobject $text -filepath $fileout -append   } write-host "total time run:"$swtotal.elapsed 

thanks! needed. set count 1 ping, , it's faster 42 second timeouts. here code might help...

$file = import-csv 'c:\temp\powershell\regcomplist.txt' $results="" $text="machine name,regkey value, runtime" $fileout = "c:\temp\powershell\regquery.csv" write-host $text out-file -filepath $fileout -inputobject $text -force $timeout = new-timespan -seconds 5 $swtotal = [diagnostics.stopwatch]::startnew() foreach ($line in $file){ $regkey = "" $keyvalue = "" $machinename = $line.machinename #trap [exception] {continue}  $key = "system\\currentcontrolset\\control\\print\\environments\\windows x64\\drivers\\version-3\\lexmark universal v2 xl" $sw = [diagnostics.stopwatch]::startnew()  $pingtest=test-connection -computername $machinename -quiet -count 1 if ($pingtest -eq $true ){     try{         #while ($sw.elapsed -lt $timeout){     $reg = [microsoft.win32.registrykey]::openremotebasekey("localmachine",$machinename)     $regkey = $reg.opensubkey($key)     $keyvalue = $regkey.getvalue('help file')      #   return     #}     #start-sleep -seconds 5     #if ($ok -ne "ok"){$keyvalue = "timed out: "+$sw.elapsed}     }     catch{     $keyvalue = "error opening registry"     }     $text = $machinename+","+$keyvalue+","+$sw.elapsed     $results += $text     #output below here:     write-host $text     out-file -inputobject $text -filepath $fileout -append   } else {write-host $machinename",doesn't ping!"} } write-host "total time run:"$swtotal.elapsed 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -