Modify the registry using PowerShell _powershell

Source: Internet
Author: User

In the following example, PowerShell modifies the registry key value, completes the security loop disable, and Loopbackcheck disable.

Copy Code code as follows:

#Security loop Disable So, can look in it on the same machine
if ($gchn = Get-itemproperty "hklm:\system\currentcontrolset\control\lsa\msv1_0\"-name "BackConnectionHostNames"- EA silentlycontinue)-eq $null) {
New-itemproperty "hklm:\system\currentcontrolset\control\lsa\msv1_0\"-propertytype multistring-value "$url"-Name " BackConnectionHostNames "
}else{
Set-itemproperty "hklm:\system\currentcontrolset\control\lsa\msv1_0\"-name "BackConnectionHostNames"-Value ($gchn . backconnectionhostnames+ "$url")
}

#disable loobback Check
if ((get-itemproperty "hklm:\system\currentcontrolset\control\lsa\"-name "DisableLoopbackCheck"-ea silentlycontinue)-eq $null) {
New-itemproperty "Hklm:\system\currentcontrolset\control\lsa\"-propertytype dword-value "1"-Name " DisableLoopbackCheck "
}

Examples to everyone, below to share some PowerShell operation of the Registry method bar

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:
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:

 
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 
} 


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:

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:

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 
}

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.