locked
Need some help with Powershell oneliner to remove .ica file extension in the registry RRS feed

  • Question

  • Goodafternoon,

    I'm searching for the answer to the following riddle. The endgoal of the oneliner is to have it remove the registry key for file extention `ica` under the HKCU:\ key. I've come as far as this:

    gci HKCU:\ -rec -ea SilentlyContinue | % { if((get-itemproperty -path $_.PsPath) - match ".ica" -and $_.name -match "fileext") {$_.PsPath} } | remove-item -whatif

    The whatif shows that it would attempt and remove the key.

    If removing -whatif, it reports ( and this is translated ): Cannot remove the subkey because the subkey does not exist.

    Another tried method: remove-itemproperty results in "the input object cannot be bound because it did not contain the information required to bind all mandataory parameters : Name | with an underlining under remove-itemproperty.

    I know i'm very close!

    details:

    Powerscript 3.x environment.

    Windows 8/10

    Wednesday, February 15, 2017 2:23 PM

Answers

  • You are nearly there but you have to pipe things through and use where-object.

    gci HKCU:\ -rec -ea 0 | Where-Object { $_.name -match 'fileext'} | get-itemproperty | Where-Object { $_.pspath -match '\.ica$'} | remove-item -whatif
    I used a regex for .ica , the dollar sign is the end of the line and the '\' escapes the dot , otherwise dot is any character.


    Cheers,

    Ruud
    Twitter:    Blog: AzureStack.Blog  LinkedIn:    
    Note: Please “Vote As Helpful” if you find my contribution useful or “Mark As Answer” if it does answer your question. That will encourage me - and others - to take time out to help you.

    • Marked as answer by bones85 Thursday, February 16, 2017 8:12 AM
    Wednesday, February 15, 2017 2:49 PM

All replies

  • You are nearly there but you have to pipe things through and use where-object.

    gci HKCU:\ -rec -ea 0 | Where-Object { $_.name -match 'fileext'} | get-itemproperty | Where-Object { $_.pspath -match '\.ica$'} | remove-item -whatif
    I used a regex for .ica , the dollar sign is the end of the line and the '\' escapes the dot , otherwise dot is any character.


    Cheers,

    Ruud
    Twitter:    Blog: AzureStack.Blog  LinkedIn:    
    Note: Please “Vote As Helpful” if you find my contribution useful or “Mark As Answer” if it does answer your question. That will encourage me - and others - to take time out to help you.

    • Marked as answer by bones85 Thursday, February 16, 2017 8:12 AM
    Wednesday, February 15, 2017 2:49 PM
  • Goodmorning!

    This will have effect on those that end with .ica, but there are also values that come in between where the Key has actual subkeys under it.

    I will be looking into the function [Microsoft.Win32.RegistryKey], it holds a delete subtree command which may proof a solution for that, if it works I'll put the results in here as well.

    Thursday, February 16, 2017 8:16 AM