From 5bd0e494f286d7ff7b8e1c4cce4e608f7b9e08e4 Mon Sep 17 00:00:00 2001 From: bdragoiu <103985076+bdragoiu@users.noreply.github.com> Date: Wed, 16 Apr 2025 14:30:30 +0200 Subject: [PATCH] Narrow by HWID --- removeGhosts.ps1 | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/removeGhosts.ps1 b/removeGhosts.ps1 index 68dbb3a..4957d78 100644 --- a/removeGhosts.ps1 +++ b/removeGhosts.ps1 @@ -24,6 +24,10 @@ This is an exact string match so "Disk" will not match "DiskDrive". This parameter will include devices that match the class name provided. This paramater needs to be specified in an array format for all the class names you want to be included. This is an exact string match so "Disk" will not match "DiskDrive". +.PARAMETER narrowByHWID +This parameter will include devices that match the partial HWID. This paramater needs to be specified in an array format for all the HWID substrings you want to be included. +Useful for matching only a specific vendor. + .PARAMETER listDevicesOnly listDevicesOnly will output a table of all devices found in this system. @@ -53,6 +57,10 @@ Lists all 'ghost' devices with a class of "Net" Lists all 'ghost' devices with a class of "Net" AND a friendly name matching "Realtek" . "removeGhosts.ps1" -listGhostDevicesOnly -narrowbyfriendlyname Realtek -narrowbyclass Net +.EXAMPLE +Lists all 'ghost' devices with a class of "Net" AND a HWID containing VEN_15AD (a.k.a VMware/Broadcom) +. "removeGhosts.ps1" -listGhostDevicesOnly -narrowByHWID VEN_15AD -narrowbyclass Net + .EXAMPLE Save the list of 'ghost' devices as an object $ghostDevices = . "removeGhosts.ps1" -listGhostDevicesOnly @@ -77,6 +85,10 @@ Remove all ghost devices EXCEPT for devices with a friendly name of "Intel" or " Remove all ghost network devices i.e. the ones with a class of "Net" . "removeGhosts.ps1" -narrowByClass Net +.EXAMPLE +Remove all ghost devices from VMWare/Broadcom. i.e "PCI\VEN_15AD" +. "removeGhosts.ps1" -narrowByHWID VEN_15AD + .EXAMPLE Remove all ghost devices without confirmation . "removeGhosts.ps1" -Force @@ -90,6 +102,7 @@ Param( [array]$NarrowByClass, [array]$FilterByFriendlyName, [array]$NarrowByFriendlyName, + [array]$NarrowByHWID, [switch]$listDevicesOnly, [switch]$listGhostDevicesOnly, [switch]$Force @@ -113,6 +126,10 @@ if ($NarrowByFriendlyName -ne $null) { write-host "NarrowByFriendlyName: $NarrowByFriendlyName" } +if ($NarrowByHWID -ne $null) { + write-host "NarrowByHWID: $NarrowByHWID" +} + if ($listDevicesOnly -eq $true) { write-host "List devices without removal: $listDevicesOnly" $removeDevices = $false @@ -133,6 +150,7 @@ function Filter-Device { ) $Class = $dev.Class $FriendlyName = $dev.FriendlyName + $HWID = $dev.HWID $matchFilter = $false if (($matchFilter -eq $false) -and ($FilterByClass -ne $null)) { @@ -173,6 +191,16 @@ function Filter-Device { } $matchFilter = !$shouldInclude } + if (($matchFilter -eq $false) -and ($NarrowByHWID -ne $null)) { + $shouldInclude = $false + foreach ($HWIDFilter in $NarrowByHWID) { + if ($HWID -like '*'+$HWIDFilter+'*') { + $shouldInclude = $true + break + } + } + $matchFilter = !$shouldInclude + } return $matchFilter }