Deleting registry keys.

Hi, Newbie here. I was laid off for a while and have really gotten rusty on my skills with Powershell which were in the fetus stage at that time. Anyway, I need to delete the contens of this registry key from 150 or so Win 7 boxes.

HKLM\SW\MS\Windows Defender\Signature Updates

I would like for the script to write to a CSV file for success or failure for each machine it touches.

I know this is a simple script, but can someone get me back in the game here?

Thanks!

March 9th, 2012 9:59pm

The simplest way to delete a reg key would be by using reg.exe.

reg delete /?

You can delete registry keys remotely and store the results in a PowerShell variable, which can then be piped out to a CSV using Export-Csv.

Free Windows Admin Tool Kit Click here and download it now
March 10th, 2012 12:03am

Hi,

You may use PSRemoteRegistry module for this. It contain Remove-RegKey cmdlet.    

  • Proposed as answer by jrv 16 hours 22 minutes ago
March 10th, 2012 11:42am

Hi,

You may use PSRemoteRegistry module for this. It contain Remove-RegKey cmdlet.    

  • Proposed as answer by jrv Sunday, May 24, 2015 2:48 PM
Free Windows Admin Tool Kit Click here and download it now
March 10th, 2012 11:42am

Hi,

We could use Remove-Item -Path hkcu:\Software\_DeleteMe to delete registry keys. By default, remove-item have no output, but we could use $? to know whether the action was successed.

For more information, please also refer to the below links:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa394600(v=vs.85).aspx

http://technet.microsoft.com/en-us/library/dd315270.aspx

Best Regards,

Yan Li

March 12th, 2012 3:49am

Thanks for the links Yan. I had an old script for removing a file and outputing the results to a TXT file. I used that script but modified it to remove the entries under the registry key that I need to delete.

Get-Content "C:\Removal\machines.txt" | % {Remove-Item -Path "HKLM:\Software\Microsoft\Dows Def\Signature Updates\*" -recurse -force
out-file -inputobject "Removed Files From $_" -append -filepath "C:\Removal\results.txt"}

It reports the entries as removed, but does nothing to the entries on the machine I am testing with. All help is appreciated.

Thanks!


Free Windows Admin Tool Kit Click here and download it now
March 14th, 2012 4:48pm

Hi,

If we can not remove the item, there are also reports that indicates that "Removed Files Form computername", but this does not mean that the key was removed.

I would like suggest you run the below code in your computer:

Get-Content "C:\test\test.txt" | % {Remove-Item -Path "HKLM:\Software\test\test"  -recurse  -Force 
 out-file -inputobject "Removed Files From $_ result: $?" -append  -FilePath "C:\test\results.txt"}

Please don't use \* at the end of the key path, we could delete the key by the directory path.

Best Regards,

Yan Li

March 15th, 2012 2:23am

I believe that Remove-Item cmdlet is not capable to delete reg key remotely. You can try following script to achieve goal.

Function DeleteRegistryKey($deleteKey)
 {
 $type = [Microsoft.Win32.RegistryHive]::LocalMachine
 $Hive = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($type, $RemoteMachine)
 $Key = $Hive.DeleteSubKey($deleteKey)
 }
 
DeleteRegistryKey HKLM:\Software\Microsoft\Dows Def\Signature Updates
Hope this helps...!!!
Free Windows Admin Tool Kit Click here and download it now
March 15th, 2012 3:50am

Bhavik,

Script looks clean, but how would you pass $remotemachine information.

I tried below but didn't work

Function DeleteRegistryKey($deleteKey, $RemoteMachine)
 {
 $type = [Microsoft.Win32.RegistryHive]::LocalMachine
 $Hive = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($type, $RemoteMachine)
 $Key = $Hive.DeleteSubKey($deleteKey)
 }
 
Foreach ($srv in get-content C:\Servers.txt) {
DeleteRegistryKey $path, $srv

}

May 24th, 2015 10:11am

It is considered rude and is against forum policy to piggyback on another user's topic.  This topic has been closed for three years.

If you have a question pleas start you own topic.  You can include a link back here if you feel it is helpful.

Be sure to post error mes

Free Windows Admin Tool Kit Click here and download it now
May 24th, 2015 10:45am

None of the answers marked here are correct based on the original question which requires remote deletion.

May 24th, 2015 10:51am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics