Forum Discussion
Com0 removal
Per
https://learn.microsoft.com/en-us/answers/questions/4263863/unable-to-remove-multiple-devices-labelled-as-com0 can you please provide the script used and your usage of the GitHub project? I have the same issue. Thanks!
2 Replies
- JessicaoldfatherBrass Contributor
The Get-PnpDevice and Remove-PnpDevice cmdlets are part of the PnPDevice module, which is available in Windows 10 version 1809 and later.
- JohnMusbachCopper 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 {}
}
}