Managing Registry with PowerShell

    Managing registry with PowerShell: Registry keys are items on Windows PowerShell drives, working with them is very similar to working with files and folders. Registry entries are properties of keys and, as such, cannot be directly browsed, we need to take a slightly different approach when working with them.

    Playing with Windows Registry is dangerous and sometimes may cause system damage. Only proceed if you know what you are doing. First try on test servers with proper registry backup.

    Get list of available providers: Get-PSDrive

    PS C:\> Get-PSDrive
    Name           Used (GB)     Free (GB) Provider      Root                                               CurrentLocation
    ----           ---------     --------- --------      ----                                               ---------------
    Alias                                  Alias
    C                  10.48         49.18 FileSystem    C:\
    Cert                                   Certificate   \
    D                   4.17               FileSystem    D:\
    Env                                    Environment
    Function                               Function
    HKCU                                   Registry      HKEY_CURRENT_USER
    HKLM                                   Registry      HKEY_LOCAL_MACHINE
    Variable                               Variable
    WSMan                                  WSMan

    Listing All Subkeys of a Registry Key:

    PS C:\> Get-ChildItem -Path hkcu:\ | Select-Object Name
    HKEY_CURRENT_USER\Control Panel
    HKEY_CURRENT_USER\Keyboard Layout
    HKEY_CURRENT_USER\Volatile Environment

    If you use Get-ChildItem -Path hkcu:\ , this will display Name and Property.

    The following command will copy all Keys and properties in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersionto HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion1

    PS C:\> Copy-Item -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion' -Destination 'HKLM:\SOFTWARE\Microsoft\Windows
    PS C:\>

    Creating Keys

    Creating new keys in the registry is simpler than creating a new item in a file system. Because all registry keys are containers, you do not need to specify the item type; you simply supply an explicit path, such as:

    PS C:\> New-Item -Path hkcu:\NewItem_DeleteMe
    Name                           Property
    ----                           --------

    Deleting Keys

    Deleting items is essentially the same for all providers. The following commands will silently remove items:
    Delete-Item -Path hkcu:\NewItem_DeleteMe

    PS C:\> Remove-Item -Path hkcu:\NewItem_DeleteMe
    PS C:\>


    © 2020, All Rights Reserved.

    We use cookies on our website. Some of them are essential for the operation of the site, while others help us to improve this site and the user experience (tracking cookies). You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.