Forum Discussion
Com0 removal
The Get-PnpDevice and Remove-PnpDevice cmdlets are part of the PnPDevice module, which is available in Windows 10 version 1809 and later.
- JohnMusbachSep 16, 2026Copper Contributor
So like this??
# Define what you are looking for and what to replace it with
$SearchText = "com0"
$ReplaceText = "com4"
$RootKeys = @("HKLM:\", "HKCU:\")
foreach ($Root in $RootKeys) {
Get-ChildItem -Path $Root -Recurse -ErrorAction SilentlyContinue | ForEach-Object {
$KeyPath = $_.PSPath
try {
$Properties = Get-ItemProperty -Path $KeyPath -ErrorAction SilentlyContinue
foreach ($Prop in $Properties.PSObject.Properties) {
if ($Prop.Value -and $Prop.Value.ToString() -match $SearchText) {
# Replace the data
$NewValue = $Prop.Value.ToString() -replace $SearchText, $ReplaceText
Set-ItemProperty -Path $KeyPath -Name $Prop.Name -Value $NewValue -Force
Write-Host "Updated Data in Key: $KeyPath | Property: $($Prop.Name)" -ForegroundColor Green
}
}
} catch {}
}
}