diff --git a/Data/USBIDs.txt b/Data/USBIDs.txt index 3db98ae..4daac79 100644 Binary files a/Data/USBIDs.txt and b/Data/USBIDs.txt differ diff --git a/Get-PC.psd1 b/Get-PC.psd1 index cf79904..944845c 100644 --- a/Get-PC.psd1 +++ b/Get-PC.psd1 @@ -12,7 +12,7 @@ RootModule = 'Get-PC.psm1' # Version number of this module. -ModuleVersion = '0.4.11' +ModuleVersion = '0.4.12' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/Private/Get-Devices.ps1 b/Private/Get-Devices.ps1 index a423cca..0165ac0 100644 --- a/Private/Get-Devices.ps1 +++ b/Private/Get-Devices.ps1 @@ -13,27 +13,26 @@ function Get-Devices { $usb | Add-Member -NotePropertyName Type -NotePropertyValue USB $usb | Add-Member -NotePropertyName AttachedComputer -NotePropertyValue $comp $usbi = 0 - foreach($item in $usb){ + $friendlyNames = $usb | ForEach-Object { $usbi++ Write-Progress -Activity "Getting devices for $name" -Status "Parsing USB Devices ($usbi/$($usb.Length)" -PercentComplete (($usbi * (80-10) / $usb.Length )+10) -ParentId 1 - $friendlyNames = FindUSBDevice -deviceID $item.'DeviceID\SerialNumber'.ToString() - - if($friendlyNames){ - $item.Manufacturer = $friendlyNames[0] - if($item.Manufacturer.Length -le 5){ - continue - } - if($item.Manufacturer.Substring(0,5) -eq '[SHS]'){ - $item.Type = 'SHS Issued USB' - $len = $item.Manufacturer.Length -1 - $item.Manufacturer = $item.Manufacturer[5..$len] -join '' - } - if($friendlyNames[1]){ - $item.Description = $friendlyNames[1] - } + Write-Output $_ + } | Select-Object -ExpandProperty 'DeviceID\SerialNumber' | FindUSBDevice + for($usbi = 0; $usbi -lt $usb.Count; $usbi++){ + Write-Progress -Activity "Getting devices for $name" -Status "Populating fields ($usbi/$($usb.Length)" -PercentComplete (($usbi * (90-80) / $usb.Length )+80) -ParentId 1 + if(!$friendlyNames[$usbi]){ continue } + $usb[$usbi].Manufacturer = $friendlyNames[$usbi].Manufacturer + if($usb[$usbi].Manufacturer.Length -le 5){ continue } + if($usb[$usbi].Manufacturer.Substring(0,5) -eq '[SHS]'){ + $usb[$usbi].Type = 'SHS Issued USB' + $len = $usb[$usbi].Manufacturer.Length -1 + $usb[$usbi].Manufacturer = $usb[$usbi].Manufacturer[5..$len] -join '' + } + if($friendlyNames[$usbi].Description){ + $usb[$usbi].Description = $friendlyNames[$usbi].Description } } - Write-Progress -Activity "Getting devices for $name" -Status 'Sorting out duplicate devices' -PercentComplete 80 -ParentId 1 + Write-Progress -Activity "Getting devices for $name" -Status 'Sorting out duplicate devices' -PercentComplete 90 -ParentId 1 $usb = $usb | Sort-Object Manufacturer,Description 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){ @@ -41,7 +40,7 @@ function Get-Devices { } } $usb = $usb | Where-Object -Property Manufacturer -NE '__DUPE__' - $usb = $usb | Sort-Object Type + $usb = $usb | Sort-Object Type,Manufacturer } catch{ @@ -289,111 +288,65 @@ Function Get-Monitor { } -function Get-VIDPID { - param ( - $deviceID - ) - - if($deviceID){ - $bool = $deviceID -match '(?<=VID_)(....)' - if(!$bool){ - return $null - } - $vid = $Matches[0] - $deviceID -match '(?<=PID_)(....)' | Out-Null - $p = $Matches[0] - return ($vid,$p) - } - else{ - return $null - } - -} function FindUSBDevice { param ( [string]$vid, [string]$p, + [Parameter(ValueFromPipeline=$true)] [string]$deviceID ) - if($deviceID){ - $bool = $deviceID -match '(?<=VID_)(....)' - if(!$bool){ - return $null - } - $vid = $Matches[0] - $deviceID -match '(?<=PID_)(....)' | Out-Null - $p = $Matches[0] - } - $SHSEquip = MatchSHSEquipment $vid $p - if($SHSEquip){ - return ($SHSEquip[0],$SHSEquip[1]) - } - $lookupTablePath = Join-Path (get-item $PSScriptRoot).Parent.FullName 'Data\USBIDs.txt' - $usbIDs = Get-Content $lookupTablePath - for ($i = 0; $i -lt $usbIDs.Count; $i++) { - if ($usbIDs[$i] -match $vid){ - - if($usbIDs[$i][0] -eq "`t"){ - - } - else{ - - $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 ($man,$null) - } - if($usbIDs[$y] -match $p){ - $dev = ($usbIDs[$y] -split ' ') - $dev = $dev[2..$dev.count] -join ' ' - return ($man,$dev) - } - - } - return ($man,$null) - } - - } - - - } -} - -function MatchSHSEquipment { - param ( - $vid, - $p - ) - $lookupTablePath = Join-Path (get-item $PSScriptRoot).Parent.FullName 'Data\SHSEquipmentLookup.txt' - $usbIDs = Get-Content $lookupTablePath - for ($i = 0; $i -lt $usbIDs.Count; $i++) { - if ($usbIDs[$i] -match $vid){ - - if($usbIDs[$i][0] -eq "`t"){ - - } - else{ - - $man = ($usbIDs[$i] -split ' ') - $man = $man[2..$man.count] -join ' ' - - for ($y = $i; $y -lt $usbIDs.Count; $y++) { - if($usbIDs[$y] -match $p){ - $dev = ($usbIDs[$y] -split ' ') - $dev = $dev[2..$dev.count] -join ' ' - return ($man,$dev) - } - - } + 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' + $usbIDs += Get-Content $lookupTablePath + } process { + if($deviceID){ + $bool = $deviceID -match '(?<=VID_)(....)' + if(!$bool){ return $null } - + $vid = $Matches[0] + $deviceID -match '(?<=PID_)(....)' | Out-Null + $p = $Matches[0] } - - + for ($i = 0; $i -lt $usbIDs.Count; $i++) { + if ($usbIDs[$i] -match $vid){ + + if($usbIDs[$i][0] -eq "`t"){ + + } + else{ + + $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 { + } - - return $null } diff --git a/Private/Get-DevicesUnplugged.ps1 b/Private/Get-DevicesUnplugged.ps1 index 83fb2fa..5f097d7 100644 --- a/Private/Get-DevicesUnplugged.ps1 +++ b/Private/Get-DevicesUnplugged.ps1 @@ -13,24 +13,23 @@ function Get-DevicesUnplugged { $usb | Add-Member -NotePropertyName Type -NotePropertyValue USB $usb | Add-Member -NotePropertyName AttachedComputer -NotePropertyValue $comp $usbi = 0 - foreach($item in $usb){ + $friendlyNames = $usb | ForEach-Object { $usbi++ - Write-Progress -Activity "Getting devices for $name" -Status "Parsing USB Devices ($usbi/$($usb.Length)" -PercentComplete (($usbi * (90-10) / $usb.Length )+10) -ParentId 1 - $friendlyNames = FindUSBDevice -deviceID $item.'DeviceID\SerialNumber'.ToString() - - if($friendlyNames){ - $item.Manufacturer = $friendlyNames[0] - if($item.Manufacturer.Length -le 5){ - continue - } - if($item.Manufacturer.Substring(0,5) -eq '[SHS]'){ - $item.Type = 'SHS Issued USB' - $len = $item.Manufacturer.Length -1 - $item.Manufacturer = $item.Manufacturer[5..$len] -join '' - } - if($friendlyNames[1]){ - $item.Description = $friendlyNames[1] - } + Write-Progress -Activity "Getting devices for $name" -Status "Parsing USB Devices ($usbi/$($usb.Length)" -PercentComplete (($usbi * (80-10) / $usb.Length )+10) -ParentId 1 + Write-Output $_ + } | Select-Object -ExpandProperty 'DeviceID\SerialNumber' | FindUSBDevice + for($usbi = 0; $usbi -lt $usb.Count; $usbi++){ + Write-Progress -Activity "Getting devices for $name" -Status "Populating fields ($usbi/$($usb.Length)" -PercentComplete (($usbi * (90-80) / $usb.Length )+80) -ParentId 1 + if(!$friendlyNames[$usbi]){ continue } + $usb[$usbi].Manufacturer = $friendlyNames[$usbi].Manufacturer + if($usb[$usbi].Manufacturer.Length -le 5){ continue } + if($usb[$usbi].Manufacturer.Substring(0,5) -eq '[SHS]'){ + $usb[$usbi].Type = 'SHS Issued USB' + $len = $usb[$usbi].Manufacturer.Length -1 + $usb[$usbi].Manufacturer = $usb[$usbi].Manufacturer[5..$len] -join '' + } + if($friendlyNames[$usbi].Description){ + $usb[$usbi].Description = $friendlyNames[$usbi].Description } } Write-Progress -Activity "Getting devices for $name" -Status 'Sorting out duplicate devices' -PercentComplete 90 -ParentId 1 @@ -56,92 +55,3 @@ function Get-DevicesUnplugged { Write-Output $out } - -function FindUSBDevice { - param ( - [string]$vid, - [string]$p, - [string]$deviceID - ) - if($deviceID){ - $bool = $deviceID -match '(?<=VID_)(....)' - if(!$bool){ - return $null - } - $vid = $Matches[0] - $deviceID -match '(?<=PID_)(....)' | Out-Null - $p = $Matches[0] - } - $SHSEquip = MatchSHSEquipment $vid $p - if($SHSEquip){ - return ($SHSEquip[0],$SHSEquip[1]) - } - $lookupTablePath = Join-Path (get-item $PSScriptRoot).Parent.FullName 'Data\USBIDs.txt' - $usbIDs = Get-Content $lookupTablePath - for ($i = 0; $i -lt $usbIDs.Count; $i++) { - if ($usbIDs[$i] -match $vid){ - - if($usbIDs[$i][0] -eq "`t"){ - - } - else{ - - $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 ($man,$null) - } - if($usbIDs[$y] -match $p){ - $dev = ($usbIDs[$y] -split ' ') - $dev = $dev[2..$dev.count] -join ' ' - return ($man,$dev) - } - - } - return ($man,$null) - } - - } - - - } -} - -function MatchSHSEquipment { - param ( - $vid, - $p - ) - $lookupTablePath = Join-Path (get-item $PSScriptRoot).Parent.FullName 'Data\SHSEquipmentLookup.txt' - $usbIDs = Get-Content $lookupTablePath - for ($i = 0; $i -lt $usbIDs.Count; $i++) { - if ($usbIDs[$i] -match $vid){ - - if($usbIDs[$i][0] -eq "`t"){ - - } - else{ - - $man = ($usbIDs[$i] -split ' ') - $man = $man[2..$man.count] -join ' ' - - for ($y = $i; $y -lt $usbIDs.Count; $y++) { - if($usbIDs[$y] -match $p){ - $dev = ($usbIDs[$y] -split ' ') - $dev = $dev[2..$dev.count] -join ' ' - return ($man,$dev) - } - - } - return $null - } - - } - - - } - - return $null -} diff --git a/patchnotes.txt b/patchnotes.txt index 7b50e10..b753f5d 100644 --- a/patchnotes.txt +++ b/patchnotes.txt @@ -1,6 +1,7 @@ Path: -Fix Enable flag also removes workstation from Disabled Computers group -Update Orion url +-Perf. Devices and Unplugged Devices are now 70% faster! Patch: 2024-10-11 -Fix no more functions create a profile on the remote machine