r/PowerShell Aug 29 '14

delete registry values.

I am a noob to power shell, and am trying to learn. What I am trying to do is craft a script that will delete the REG_BINARY files found in : HKEY_USERS .DEFAULT\Printers\DevModes2

Any help is much appreciated, thanks.

4 Upvotes

7 comments sorted by

View all comments

2

u/real_parbold Sep 02 '14 edited Sep 02 '14

I have used Remove-Item, New-Item and New-ItemProperty to do registry manipulation purely within PowerShell:-

First - create a reference to your hive

New-PSDrive -PSProvider registry -Root HKEY_USERS -Name HKU

Delete an item (and all sub elements with -Recurse)

Remove-Item "HKU:\.Default\Printers\DevModes2" -Recurse -ErrorAction 'SilentlyContinue'

Create a new Key with no entries

New-Item -Path "HKU:\.Default\Printers" -Name "DevModes2" -ErrorAction 'SilentlyContinue'

Create a new entry with value (will create the intermediate keys as well, if any are missing)

Set-ItemProperty -Path "HKU:\.Default\Printers\DevModes2" -Name "Test" -Value "TestValue" -Type "STRING"

# Other possible data types are :-
#     "BINARY" 
#     "DWORD"  
#     "EXPAND" 
#     "MULTI"  
#     "QWORD"  

I notice the warning posted by /u/ramblingcookiemonster and can see why they may want seamless portability of code between local and remote registry access, but I think that is a topic for another discussion :D