Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions removeGhosts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -90,6 +102,7 @@ Param(
[array]$NarrowByClass,
[array]$FilterByFriendlyName,
[array]$NarrowByFriendlyName,
[array]$NarrowByHWID,
[switch]$listDevicesOnly,
[switch]$listGhostDevicesOnly,
[switch]$Force
Expand All @@ -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
Expand All @@ -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)) {
Expand Down Expand Up @@ -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
}

Expand Down