When you don't need to get the registry data type and as long as the value is very simple: you can use Get-itemproperty:
Copy Code code as follows:
Get-itemproperty-path Hklm:\software\microsoft\windows\currentversion\run
If you need to get the data type, you need only a few more steps:
Copy Code code as follows:
$key = Get-item-path Hklm:\software\microsoft\windows\currentversion\run
$key. GetValueNames () |
Foreach-object {
$ValueName = $_
$RV = 1 | Select-object-property Name, Type, Value
$rv. Name = $ValueName
$rv. Type = $key. Getvaluekind ($ValueName)
$rv. Value = $key. GetValue ($ValueName)
$rv
}
Access registry key values
In PowerShell, a user can access a registry key by using a virtual drive similar to HKCU: (as HKEY_CURRENT_USER) and HKLM: (on behalf of Hkey_local_matchine).
such as: Dir Registry::hkey_local_machine\software
In this way, users can easily copy and paste the key values in the registry, the user can obtain the registered file suffix through the following command:
Copy Code code as follows:
Dir registry::hkey_classes_root\.*-name | Sort-object
Reading registry key Values
In PowerShell, the user can process the contents of the registry as a virtual drive
The following get-regidtryvalues function enumerates all the key values stored under a registry key, as shown in the complete code:
Copy Code code as follows:
function Get-registryvalues ($key) {
(Get-item $key). GetValueNames ()
}
Get-registryvalues hklm:\software\microsoft\windows\currentversion
Get-registryvalue reads any registry key value and returns its contents, as shown in the complete code:
function Get-registryvalue ($key, $value) {
(Get-itemproperty $key $value). $value
}
Get-registryvalue ' Hklm:\software\microsoft\windows\currentversion '
Sm_gamesname
Write registry key value
Adding or modifying registry keys is also handy in PowerShell, and the following is the complete code that creates the name Set-registryvalue function to manipulate the registry key value:
Copy Code code as follows:
function Set-registryvalue ($key, $name, $value, $type = "String") {
if ((Test-path $key)-eq $false) {MD $key | Out-null}
Set-itemproperty $key $name $value-type $type
}
Set-registryvalue HKCU:\SOFTWARE\TESTABC myvalue Hello
Set-registryvalue HKCU:\SOFTWARE\TESTABC myvalue Dword
Set-registryvalue hkcu:\software\testabc myvalue '
([byte[]][char[]] "Hello" Binary
Remove registry key value
By Remove-item Delete the target registry key, the complete code for the function Remove-registrykey is as follows:
Copy Code code as follows:
function Remove-registrykey ($key) {
Remove-item $key-force
}
To delete a registry value through the Remove-itemproperty function, the complete code looks like this:
function Remove-registryvalue ($key, $value) {
Remove-itemproperty $key $value
}
Supports all PS versions