Optimizations in Devices
This commit is contained in:
parent
b7fdd6656f
commit
78f7abf82a
|
|
@ -33,15 +33,7 @@ function Get-Devices {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Write-Progress -Activity "Getting devices for $name" -Status 'Sorting out duplicate devices' -PercentComplete 90 -ParentId 1
|
Write-Progress -Activity "Getting devices for $name" -Status 'Sorting out duplicate devices' -PercentComplete 90 -ParentId 1
|
||||||
$usb = $usb | Sort-Object Manufacturer,Description
|
$usb = $usb | Sort-Object Manufacturer,Description -Unique | Sort-Object Type,Manufacturer
|
||||||
for ($i = 0; $i -lt $usb.Count - 1; $i++) {
|
|
||||||
if($usb[$i].Manufacturer -eq $usb[$i+1].Manufacturer -and $usb[$i].Description -eq $usb[$i+1].Description){
|
|
||||||
$usb[$i].Manufacturer = '__DUPE__'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$usb = $usb | Where-Object -Property Manufacturer -NE '__DUPE__'
|
|
||||||
$usb = $usb | Sort-Object Type,Manufacturer
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch{
|
catch{
|
||||||
Write-warning 'Unable to grab USB info'
|
Write-warning 'Unable to grab USB info'
|
||||||
|
|
@ -298,50 +290,42 @@ function FindUSBDevice {
|
||||||
[string]$deviceID
|
[string]$deviceID
|
||||||
)
|
)
|
||||||
begin {
|
begin {
|
||||||
# Start with SHS Equipment override
|
|
||||||
$lookupTablePath = Join-Path (get-item $PSScriptRoot).Parent.FullName 'Data\SHSEquipmentLookup.txt'
|
|
||||||
$usbIDs = Get-Content $lookupTablePath
|
|
||||||
$lookupTablePath = Join-Path (get-item $PSScriptRoot).Parent.FullName 'Data\USBIDs.txt'
|
$lookupTablePath = Join-Path (get-item $PSScriptRoot).Parent.FullName 'Data\USBIDs.txt'
|
||||||
$usbIDs += Get-Content $lookupTablePath
|
$usbIDs += Get-Content $lookupTablePath
|
||||||
|
# Overwrite any USBIDs with SHS Overrides
|
||||||
|
$lookupTablePath = Join-Path (get-item $PSScriptRoot).Parent.FullName 'Data\SHSEquipmentLookup.txt'
|
||||||
|
$usbIDs = Get-Content $lookupTablePath
|
||||||
|
|
||||||
|
# Populate lookup table from file contents
|
||||||
|
$usbIDTable = @{}
|
||||||
|
foreach ($line in $usbIDs) {
|
||||||
|
# Skip comments
|
||||||
|
if ($line -match "^#") { continue }
|
||||||
|
if ($line -match "^[\t]([0-9a-f]{4})\s+([^#]+)") {
|
||||||
|
$usbIDTable[$vid]['Devices'][$Matches[1]] = $Matches[2]
|
||||||
|
continue
|
||||||
|
# If line doesn't match device id definition, see if it's a vendor definition
|
||||||
|
} else {
|
||||||
|
if (-not ($line -match "^([0-9a-f]{4})\s+([^#]+)")) { continue }
|
||||||
|
$usbIDTable[$Matches[1]] = @{
|
||||||
|
Name = $Matches[2]
|
||||||
|
Devices = @{}
|
||||||
|
}
|
||||||
|
$vid = $Matches[1]
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
} process {
|
} process {
|
||||||
if($deviceID){
|
if($deviceID){
|
||||||
$bool = $deviceID -match '(?<=VID_)(....)'
|
if (-not( $deviceID -match '(?<=VID_)(....)' )) { return $null }
|
||||||
if(!$bool){
|
|
||||||
return $null
|
|
||||||
}
|
|
||||||
$vid = $Matches[0]
|
$vid = $Matches[0]
|
||||||
$deviceID -match '(?<=PID_)(....)' | Out-Null
|
$deviceID -match '(?<=PID_)(....)' | Out-Null
|
||||||
$p = $Matches[0]
|
$p = $Matches[0]
|
||||||
}
|
}
|
||||||
for ($i = 0; $i -lt $usbIDs.Count; $i++) {
|
if (-not $usbIDTable[$vid]) { return $null }
|
||||||
if (-not ($usbIDs[$i] -match $vid)){ continue }
|
return @{
|
||||||
|
Manufacturer = $usbIDTable[$vid]['Name']
|
||||||
if($usbIDs[$i][0] -eq "`t"){ continue }
|
Description = $usbIDTable[$vid]['Devices'][$p]
|
||||||
|
|
||||||
$man = ($usbIDs[$i] -split ' ')
|
|
||||||
$man = $man[2..$man.count] -join ' '
|
|
||||||
|
|
||||||
for ($y = $i+1; $y -lt $usbIDs.Count; $y++) {
|
|
||||||
if($usbIDs[$y][0] -ne "`t"){
|
|
||||||
return @{
|
|
||||||
Manufacturer = $man
|
|
||||||
Description = $null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if($usbIDs[$y] -match $p){
|
|
||||||
$dev = ($usbIDs[$y] -split ' ')
|
|
||||||
$dev = $dev[2..$dev.count] -join ' '
|
|
||||||
return @{
|
|
||||||
Manufacturer = $man
|
|
||||||
Description = $dev
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return @{
|
|
||||||
Manufacturer = $man
|
|
||||||
Description = $null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} end {
|
} end {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
Patch
|
||||||
|
-Fix Devices and DevicesUnplugged 1.4x speedup
|
||||||
|
|
||||||
Patch 2025-2-13
|
Patch 2025-2-13
|
||||||
-Add HostnamesByPrinter to list hostnames with printer installed
|
-Add HostnamesByPrinter to list hostnames with printer installed
|
||||||
-Add JobsPrinters to query many printers faster
|
-Add JobsPrinters to query many printers faster
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue