Delete Registry property

Hi, I am trying to delete some Item Properties inside a Key and I can’t figure out a way, i am fairly new to using powershell and can’t understand why

I am trying to remove every item property inside key SiS except Reg1, Reg5

the commands I tried:

Remove-ItemProperty -path Registry::HKLM\SAM\SiS -name * -exclude Reg1,Reg5

→ this deletes everything inside SiS -exclude doesn’t seem to work

Get-ItemProperty Registry::HKLM\SAM\SiS | Select * -exclude Reg1,Reg5 | Remove-ItemProperty -name *

→ this doesn’t do anything

The problem is that -Exclude qualifies the path, not the properties.

Solution based on this Reddit post:

$path = 'HKLM:\SAM\SiS'
(Get-Item -Path $path).GetValueNames() | 
    Where-Object {$_ -notin 'Reg1','Reg5'} | 
       ForEach-Object { Remove-ItemProperty -Path $path -Name $_ }