alter this line to not remove ending with -500 but otherwise remove all items??

This topic contains 2 replies, has 3 voices, and was last updated by  Curtis Smith 2 years, 8 months ago.

  • Author
  • #31756


    I have this line to remove all the registry entries in this key:

    Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\NetCache\PurgeAtNextLogoff\ -name s* -whatif

    I want to exclude the one with -500 at the end but using -exclude *-500 does not work, how do I revise this line to remove all entries but the one ending with -500??

    I tried using -filter but I got an error saying the provider does not support the use of filters.

    Any other ways I can get the line to remove all items but the one ending in -500??

    Thank you, Tom

  • #31766

    Mark Hammonds

    Do a get-item and store them in a variable then use a for each loop. inside the loop use an if statement

    if(!( $item -like "*-500")){
    Remove-item bla bla bla

    I'm on my iPad I can write it when I get to my pc if no ne else chimes in.

  • #31767

    Curtis Smith

    I would take this approach

    $RegPath =  "HKCU:\SOFTWARE\Test"
    Get-Item -Path $RegPath |
    Select-Object -ExpandProperty Property |
    Where-Object {$_ -like 's*' -and $_ -notlike '*-500'} |
    ForEach-Object {
                    Remove-ItemProperty -Path $RegPath -Name $_ -WhatIf

You must be logged in to reply to this topic.