Removal of Registry Value - possibly a hidden value?

Hello,
I am trying to write some code to remove a registry value from a machine if the value exists, and I am testing with a machine that I am 100% positive contains the value. However, I keep getting the error “Property does not exist at path” - I pasted the error at the bottom of this post. I know it exists - is it possible that it is hidden or protected or something to that effect? Thanks for any assistance, here is my code, and the error below:

"OU=TPOS,OU=DEV,OU=POS,DC=Company,DC=net","OU=TPOS,OU=QA,OU=POS,DC=Company,DC=net" | ForEach-Object {Get-ADComputer -Filter "Name –like 'P0*'" -SearchBase $_ | Select-Object –ExpandProperty Name | Add-Content C:\Temp\TPOSLower.txt} 
Get-Content C:\Temp\TPOSLower.txt | ForEach-Object {If(Test-Connection -ComputerName $_ -Quiet) {Remove-ItemProperty -Name Transaction_Count -Path HKLM:\Software\Company\ImageInfo}}

Remove-ItemProperty : Property Transaction_Count does not exist at path
HKEY_LOCAL_MACHINE\Software\Company\ImageInfo.
At line:1 char:99

  • … $_ -Quiet) {Remove-ItemProperty -Name Transaction_Count -Path HKLM:\S …
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (Transaction_Count:String) [Remove-ItemProperty], PSArgumentException
    • FullyQualifiedErrorId : System.Management.Automation.PSArgumentException,Microsoft.PowerShell.Commands.RemoveIte
      mPropertyCommand

Hi Rayen,

There’s nothing in your code that is accessing the remote computers registry, so this will always run on your local machine.

You can carry out the removal action either by calculating the remote registry path and specifying it in your command, or alternatively use invoke-comand with -Computername parameter and run the removal part within the -Scriptblock setting.

Fixed!!! Wow, thank you. I appreciate the help very much. Here is the updated code, for anyone else that may run into this (of course I am a n00b, so maybe it’s just me) :slight_smile:

"OU=TPOS,OU=DEV,OU=POS,DC=Company,DC=net","OU=TPOS,OU=QA,OU=POS,DC=Company,DC=net" | ForEach-Object {Get-ADComputer -Filter "Name –like 'P0*'" -SearchBase $_ | Select-Object –ExpandProperty Name | Add-Content C:\Temp\TPOSLower.txt} 
Get-Content C:\Temp\TPOSLower.txt | ForEach-Object {If(Test-Connection -ComputerName $_ -Quiet) {Invoke-Command -Computer $_ -ScriptBlock {Remove-ItemProperty -Name Transaction_Count -Path HKLM:\Software\Company\ImageInfo}}}