Devices is now 70% faster!
This commit is contained in:
parent
4d1276f727
commit
d25282f2f1
BIN
Data/USBIDs.txt
BIN
Data/USBIDs.txt
Binary file not shown.
|
|
@ -12,7 +12,7 @@
|
||||||
RootModule = 'Get-PC.psm1'
|
RootModule = 'Get-PC.psm1'
|
||||||
|
|
||||||
# Version number of this module.
|
# Version number of this module.
|
||||||
ModuleVersion = '0.4.11'
|
ModuleVersion = '0.4.12'
|
||||||
|
|
||||||
# Supported PSEditions
|
# Supported PSEditions
|
||||||
# CompatiblePSEditions = @()
|
# CompatiblePSEditions = @()
|
||||||
|
|
|
||||||
|
|
@ -13,27 +13,26 @@ function Get-Devices {
|
||||||
$usb | Add-Member -NotePropertyName Type -NotePropertyValue USB
|
$usb | Add-Member -NotePropertyName Type -NotePropertyValue USB
|
||||||
$usb | Add-Member -NotePropertyName AttachedComputer -NotePropertyValue $comp
|
$usb | Add-Member -NotePropertyName AttachedComputer -NotePropertyValue $comp
|
||||||
$usbi = 0
|
$usbi = 0
|
||||||
foreach($item in $usb){
|
$friendlyNames = $usb | ForEach-Object {
|
||||||
$usbi++
|
$usbi++
|
||||||
Write-Progress -Activity "Getting devices for $name" -Status "Parsing USB Devices ($usbi/$($usb.Length)" -PercentComplete (($usbi * (80-10) / $usb.Length )+10) -ParentId 1
|
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()
|
Write-Output $_
|
||||||
|
} | Select-Object -ExpandProperty 'DeviceID\SerialNumber' | FindUSBDevice
|
||||||
if($friendlyNames){
|
for($usbi = 0; $usbi -lt $usb.Count; $usbi++){
|
||||||
$item.Manufacturer = $friendlyNames[0]
|
Write-Progress -Activity "Getting devices for $name" -Status "Populating fields ($usbi/$($usb.Length)" -PercentComplete (($usbi * (90-80) / $usb.Length )+80) -ParentId 1
|
||||||
if($item.Manufacturer.Length -le 5){
|
if(!$friendlyNames[$usbi]){ continue }
|
||||||
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($item.Manufacturer.Substring(0,5) -eq '[SHS]'){
|
if($friendlyNames[$usbi].Description){
|
||||||
$item.Type = 'SHS Issued USB'
|
$usb[$usbi].Description = $friendlyNames[$usbi].Description
|
||||||
$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 'Sorting out duplicate devices' -PercentComplete 90 -ParentId 1
|
||||||
Write-Progress -Activity "Getting devices for $name" -Status 'Sorting out duplicate devices' -PercentComplete 80 -ParentId 1
|
|
||||||
$usb = $usb | Sort-Object Manufacturer,Description
|
$usb = $usb | Sort-Object Manufacturer,Description
|
||||||
for ($i = 0; $i -lt $usb.Count - 1; $i++) {
|
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){
|
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 | Where-Object -Property Manufacturer -NE '__DUPE__'
|
||||||
$usb = $usb | Sort-Object Type
|
$usb = $usb | Sort-Object Type,Manufacturer
|
||||||
|
|
||||||
}
|
}
|
||||||
catch{
|
catch{
|
||||||
|
|
@ -289,32 +288,20 @@ 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 {
|
function FindUSBDevice {
|
||||||
param (
|
param (
|
||||||
[string]$vid,
|
[string]$vid,
|
||||||
[string]$p,
|
[string]$p,
|
||||||
|
[Parameter(ValueFromPipeline=$true)]
|
||||||
[string]$deviceID
|
[string]$deviceID
|
||||||
)
|
)
|
||||||
|
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){
|
if($deviceID){
|
||||||
$bool = $deviceID -match '(?<=VID_)(....)'
|
$bool = $deviceID -match '(?<=VID_)(....)'
|
||||||
if(!$bool){
|
if(!$bool){
|
||||||
|
|
@ -324,12 +311,6 @@ function FindUSBDevice {
|
||||||
$deviceID -match '(?<=PID_)(....)' | Out-Null
|
$deviceID -match '(?<=PID_)(....)' | Out-Null
|
||||||
$p = $Matches[0]
|
$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++) {
|
for ($i = 0; $i -lt $usbIDs.Count; $i++) {
|
||||||
if ($usbIDs[$i] -match $vid){
|
if ($usbIDs[$i] -match $vid){
|
||||||
|
|
||||||
|
|
@ -343,57 +324,29 @@ function FindUSBDevice {
|
||||||
|
|
||||||
for ($y = $i+1; $y -lt $usbIDs.Count; $y++) {
|
for ($y = $i+1; $y -lt $usbIDs.Count; $y++) {
|
||||||
if($usbIDs[$y][0] -ne "`t"){
|
if($usbIDs[$y][0] -ne "`t"){
|
||||||
return ($man,$null)
|
return @{
|
||||||
|
Manufacturer = $man
|
||||||
|
Description = $null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if($usbIDs[$y] -match $p){
|
if($usbIDs[$y] -match $p){
|
||||||
$dev = ($usbIDs[$y] -split ' ')
|
$dev = ($usbIDs[$y] -split ' ')
|
||||||
$dev = $dev[2..$dev.count] -join ' '
|
$dev = $dev[2..$dev.count] -join ' '
|
||||||
return ($man,$dev)
|
return @{
|
||||||
|
Manufacturer = $man
|
||||||
|
Description = $dev
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return ($man,$null)
|
return @{
|
||||||
|
Manufacturer = $man
|
||||||
|
Description = $null
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} end {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -13,24 +13,23 @@ function Get-DevicesUnplugged {
|
||||||
$usb | Add-Member -NotePropertyName Type -NotePropertyValue USB
|
$usb | Add-Member -NotePropertyName Type -NotePropertyValue USB
|
||||||
$usb | Add-Member -NotePropertyName AttachedComputer -NotePropertyValue $comp
|
$usb | Add-Member -NotePropertyName AttachedComputer -NotePropertyValue $comp
|
||||||
$usbi = 0
|
$usbi = 0
|
||||||
foreach($item in $usb){
|
$friendlyNames = $usb | ForEach-Object {
|
||||||
$usbi++
|
$usbi++
|
||||||
Write-Progress -Activity "Getting devices for $name" -Status "Parsing USB Devices ($usbi/$($usb.Length)" -PercentComplete (($usbi * (90-10) / $usb.Length )+10) -ParentId 1
|
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()
|
Write-Output $_
|
||||||
|
} | Select-Object -ExpandProperty 'DeviceID\SerialNumber' | FindUSBDevice
|
||||||
if($friendlyNames){
|
for($usbi = 0; $usbi -lt $usb.Count; $usbi++){
|
||||||
$item.Manufacturer = $friendlyNames[0]
|
Write-Progress -Activity "Getting devices for $name" -Status "Populating fields ($usbi/$($usb.Length)" -PercentComplete (($usbi * (90-80) / $usb.Length )+80) -ParentId 1
|
||||||
if($item.Manufacturer.Length -le 5){
|
if(!$friendlyNames[$usbi]){ continue }
|
||||||
continue
|
$usb[$usbi].Manufacturer = $friendlyNames[$usbi].Manufacturer
|
||||||
}
|
if($usb[$usbi].Manufacturer.Length -le 5){ continue }
|
||||||
if($item.Manufacturer.Substring(0,5) -eq '[SHS]'){
|
if($usb[$usbi].Manufacturer.Substring(0,5) -eq '[SHS]'){
|
||||||
$item.Type = 'SHS Issued USB'
|
$usb[$usbi].Type = 'SHS Issued USB'
|
||||||
$len = $item.Manufacturer.Length -1
|
$len = $usb[$usbi].Manufacturer.Length -1
|
||||||
$item.Manufacturer = $item.Manufacturer[5..$len] -join ''
|
$usb[$usbi].Manufacturer = $usb[$usbi].Manufacturer[5..$len] -join ''
|
||||||
}
|
|
||||||
if($friendlyNames[1]){
|
|
||||||
$item.Description = $friendlyNames[1]
|
|
||||||
}
|
}
|
||||||
|
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
|
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
|
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
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
Path:
|
Path:
|
||||||
-Fix Enable flag also removes workstation from Disabled Computers group
|
-Fix Enable flag also removes workstation from Disabled Computers group
|
||||||
-Update Orion url
|
-Update Orion url
|
||||||
|
-Perf. Devices and Unplugged Devices are now 70% faster!
|
||||||
|
|
||||||
Patch: 2024-10-11
|
Patch: 2024-10-11
|
||||||
-Fix no more functions create a profile on the remote machine
|
-Fix no more functions create a profile on the remote machine
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue