Powershell – Working with Registry


Listing Registry Keys

Get-ChildItem
Registry keys and property can be displayed using Get-ChildItem. To see also hidden and system items, type:

Get-ChildItem HKCU:\ -Force

To query all underlined registry keys and search for keys with less than one subkey with ten values, type:

Get-ChildItem HKCU:\ -Force -Recurse | Where-Object -FilterScript {($_.SubKeyCount -le 1) -and ($_.ValueCount -eq 10)}

To List all Key properties, type:

Get-ChildItem HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion | Select-Object -ExpandProperty Property

The same in a more readable form:

Get-ItemProperty HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion | Select-Object -ExpandProperty Property

 
Copy Registry Key
Copy-Item
To coy a key in another location, type:

Copy-Item -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion' -Destination HKCU:

To copy the key and all is content, type:

Copy-Item -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion' -Destination HKCU: -Recurse

 
Create Registry Key
New-Item
To create a new Key, type:

New-Item -Path HKLM:\Software\Microsoft\Rpc\Internet

To create a new key property, type

New-ItemProperty -Path HKLM:\Software\Microsoft\Rpc\Internet -Name Ports -PropertyType MultiString -Value 5984-5994

Note: For key properties be aware:
REG_SZ = String
REG_DWORD = DWord
REG_QWORD = QWord
REG_MULTI_SZ = MultiString
REG_BINARY = Binary
 
Delete Registry Key
Remove-Item
To delete a key, type:

New-Item -Path HKLM:\Software\Microsoft\Rpc\Internet

If subKety exist and the –Recurse parameter is not passed you will be prompted to confirm subKeys deletion.
 

In Depth
http://technet.microsoft.com/en-us/library/dd315270.aspx
http://technet.microsoft.com/en-us/library/dd315394.aspx
http://blogs.technet.com/b/heyscriptingguy/archive/2012/05/07/use-the-powershell-registry-provider-to-simplify-registry-access.aspx
http://blogs.technet.com/b/heyscriptingguy/archive/2012/03/18/use-powershell-to-find-and-remove-remote-registry-entries.aspx

Tested With
PowerShell 4.0

Advertisements
Categories: Powershell | Leave a comment

Post navigation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: