PowerShell tips to get the type of registry value _powershell

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.