Reputation: 23
I'm trying to make a PowerShell script that checks a set registry key for a range of names that start the same. That part I have working fine. I also need this script to than remove those items from that registry and I am having trouble remembering how to pass the names of all items I find so that Remove-ItemProperty will work. This is what I have.
$Reg = 'HKCU:\Software\Microsoft\Windows NT\CurrentVersion\Devices'
Get-ItemProperty -Path $Reg | Select-Object IS* | ForEach-Object {$PSItem.Name} | Remove-ItemProperty -Path $Reg -Name $name
The message I get is that Name is null so I'm not storing the names correctly. They display correctly if I just run the first two pipes.
Upvotes: 2
Views: 2499
Reputation: 7046
Try this. Had to re-write a bit to make the property name stick.
Get-Item -Path "$Reg" | Select-Object -ExpandProperty Property |
ForEach-Object {if ($_ -match "IS*"){Remove-ItemProperty -Path "$Reg" -Name "$_"}}
Upvotes: 1