EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials PowerShell Tutorial PowerShell Registry
Secondary Sidebar
PowerShell Tutorial
  • Basics
    • PowerShell Restart Service
    • PowerShell comment
    • PowerShell Map Network Drive
    • PowerShell Append to File
    • PowerShell print
    • What is PowerShell
    • Uses Of Powershell
    • PowerShell Empire
    • PowerShell Parameter
    • PowerShell Stop Service
    • PowerShell Versions
    • How To Install PowerShell
    • PowerShell uninstall module
    • How to Use PowerShell?
    • PowerShell Logging
    • PowerShell Tools
    • PowerShell Commands
    • PowerShell Version Command
    • PowerShell Administrator
    • PowerShell Modules
    • PowerShell Registry
    • PowerShell block Comment
    • PowerShell Verbs
    • PowerShell list
    • PowerShell add user to group
    • PowerShell Write to Console
    • Variable in PowerShell
    • PowerShell New Line
    • PowerShell prompt for input
    • PowerShell File Extension
    • Powershell Remotesigned
    • PowerShell Write to File
    • PowerShell Ping
    • PowerShell wget
    • PowerShell Global variable
    • PowerShell Get-ADGroup
    • Array in PowerShell
    • PowerShell Multidimensional Array
    • PowerShell Array of Strings
    • PowerShell? join array
    • Useful PowerShell Scripts
    • String in PowerShell
    • PowerShell Switch Statement
    • PowerShell Function Parameters
    • PowerShell vs PowerShell ISE
    • PowerShell test-connection
    • PowerShell Test-NetConnection
    • PowerShell GUI
    • PowerShell Variable in String
    • PowerShell Active Directory
  • Variables
    • PowerShell Variables
    • PowerShell Environment Variables
    • PowerShell set environment variable
    • Hashtable in PowerShell
    • Set Variable in PowerShell
  • Operators
    • PowerShell Operators
    • Comparison Operators in PowerShell
    • Logical Operators in PowerShell
    • PowerShell Boolean
    • PowerShell Like Operator
  • cmdlet
    • PowerShell Wait
    • PowerShell Match
    • cmdlets in PowerShell
    • Start PowerShell from cmd
    • Add-Content in PowerShell
    • Get Help in PowerShell
    • PowerShell Copy-Item
    • PowerShell Remove-Item
    • PowerShell Move-Item
    • Get Command in PowerShell
    • PowerShell Run Command
    • Windows PowerShell ISE
    • Windows Powershell Commands
    • WinRM PowerShell
    • PowerShell Date
    • Powershell Write-Host
    • PowerShell Get-ChildItem
    • PowerShell Sort-Object
    • PowerShell Where Object
    • PowerShell Set-Content
    • PowerShell Set-Location
    • PowerShell Invoke-Command
    • PowerShell Invoke-Webrequest
    • PowerShell Get-Location
    • PowerShell Get-Date
    • PowerShell Get-Service
    • PowerShell Test-Path
    • Powershell Module Path
    • PowerShell Out-File
    • PowerShell if File Exists
    • Powershell Copy File
    • PowerShell Delete File
    • PowerShell New-Item
    • PowerShell Rename-Item
    • PowerShell ComputerName
    • PowerShell Get-Content
    • PowerShell Get-Item
    • PowerShell Get-ADUser
    • PowerShell Grep
    • PowerShell Concatenate String
    • PowerShell Get-Process
    • PowerShell Count
    • PowerShell pause
  • Control Statements
    • If Statement in PowerShell
    • If Else in PowerShell
    • Else If in PowerShell
    • Loops in PowerShell
    • For loop in PowerShell
    • PowerShell While Loop
    • PowerShell do while
    • PowerShell Loop through Array
    • PowerShell add to array
    • PowerShell ForEach Loop
    • PowerShell Break
    • PowerShell Continue
    • Switch Case in PowerShell
    • PowerShell If-Not
    • Try-catch in PowerShell
  • Functions
    • PowerShell Functions
    • PowerShell String Functions
    • powershell nslookup
    • PowerShell here string
    • PowerShell Wildcards
    • Regex in PowerShell
    • PowerShell not like
    • PowerShell Filter
    • PowerShell Sleep
    • PowerShell where
    • PowerShell join string
    • PowerShell Exit
    • PowerShell null
    • PowerShell Dictionary
    • PowerShell Location
    • PowerShell Start-Service
    • PowerShell is not digitally signed
    • PowerShell Uptime
    • PowerShell Create Directory
    • PowerShell Trim
    • PowerShell Join-Path
    • PowerShell Execution Policy
    • PowerShell SubString
    • PowerShell Format Table
    • PowerShell Import Module
    • PowerShell ForEach Object
    • PowerShell Alias
    • PowerShell Scheduled Task
    • PowerShell Convert String to Date
    • PowerShell Split String
    • PowerShell Multiline String
    • PowerShell MultiLine Comment
    • PowerShell Rename Folder
    • PowerShell Delete Folder
    • PowerShell String Replace
    • PowerShell join
    • PowerShell xcopy
    • PowerShell Base64
    • PowerShell Tail
    • PowerShell User List
    • PowerShell remove User from group
    • PowerShell JSON Format
    • PowerShell Send Mail
    • PowerShell Convert to String
    • PowerShell Start-Process
    • PowerShell change directory
    • PowerShell Open File
    • PowerShell Batch File
    • PowerShell ZIP
    • PowerShell unzip
    • PowerShell XML
    • PowerShell XML Parsing
    • Remote PowerShell
    • PowerShell Escape Character
    • PowerShell scriptblock
    • PowerShell Executable Location
    • PowerShell Import-CSV?
    • PowerShell Export CSV
  • Interview Questions
    • PowerShell Interview Questions

Related Courses

Shell Scripting Course

All in One Data Science Courses

Data Visualization Courses

PowerShell Registry

By Priya PedamkarPriya Pedamkar

PowerShell Registry

Introduction to PowerShell Registry

In windows operating systems, all the information related to all software and hardware such as settings, the value of software, and other options is stored in a database like called Registry. Whenever a program gets installed, a subkey with information related to the program like location or version is created and added to the registry. These settings can be found or modified in the Registry Editor. Fixing some errors related to software or operating system involves working with the registry to modify their values. Though the users can interact with the registry using Regedit or reg.exe, PowerShell has many cmdlets that can be used by the administrators to connect and work with the registry entries. This article will explain in detail how PowerShell can be used to interact with the registry.

Syntax

Below are the syntax of PowerShell Registry:

Syntax #1

To find the path of the registry on a local machine, use the below cmdlet

Code:

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

get-psdrive

Output:

powershell registry1

Syntax #2

To get the registry keys that are available in the registry the following cmdlet can be used

Code:

Get-ChildItem -Path HKCU:\ | Select-Object Name

Output:

powershell registry2

Syntax #3

The following are the keys present in the HKCU registry

For HKLM registry keys

Code:

Get-ChildItem -Path HKLM:\ | Select-Object Name

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (86,294 ratings)

Output:

powershell registry3

Creating new Keys in the PowerShell Registry

The registry is like a folder or a file system and registry entries and their values are the properties of the registry.

To create a new key in the registry the following cmdlet can be used.

Code:

New-Item -Path HKCU:\TestRegistry

Or

New-Item -Path Registry::HKCU\TestRegistry

Output:

powershell registry4

Explanation: In the above screenshot, the new key TestRegistry is added to the HKCU registry.

Deleting Keys

The below cmdlet can be used to delete the registry keys.

Code:

Remove-Item -Path HKCU:\TestRegistry

or

Remove-Item -Path 'HKCU:\TestRegistry'

Output:

powershell registry5

Explanation: The specified entry is deleted from the registry. To remove the keys that are under a specific key, then the recurse parameter must be used in the remove cmdlet.

Navigating between Registry Entries

As discussed earlier, registry entries are keys to the registry and cant be accessed directly.

Code:

Get-Item -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\dwm |Select-Object -ExpandProperty Property

Or

Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\dwm |Select-Object

Output:

powershell registry6

To get the properties of the current location, the below cmdlet can be used

Code:

Get-ItemProperty -Path

Output:

powershell registry7

A specific entry can be retrieved directly by specifying the name along with Name parameter

Code:

Get-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion -Name ProgramFilesDir

Output:

powershell registry8

To change the value of a key

Code:

write-host "Welcome to demo of Setting a value"
Write-Host "Chnaging the value of onedrive"
$value = Get-ItemProperty -Path HKCU:\Environment -Name OneDrive
Write-Host "Before changing" $value
$newvalue = $value.OneDrive += ";C:\test"
Set-ItemProperty -Path HKCU:\Environment -Name OneDrive -Value $newvalue
$value = Get-ItemProperty -Path HKCU:\Environment -Name OneDrive
write-host "After change" $value

Output:

change the value of a key

Creating new Registry Entries

A new entry can be created as follows.

Code:

Write-Host "Creating new registry entries"
write-host "current values in environment registry"
Get-ItemProperty -Path HKCU:\Environment
New-ItemProperty -Path HKLM:\Environment -Name PowerShellPath -PropertyType String -Value $PSHome
Write-Host "Value is added"
Write-Host "after adding values in environment registry"
Get-ItemProperty -Path HKCU:\Environment

Output:

Registry Entries

Type Value
Binary Denotes Binary Data
DWord Denotes int32 number
Expand String String with environment variables
MultiString Denotes Multiline string
String Denotes a normal string
Qword Denotes 8-byte binary data

Renaming entries

Code:

write-host "Welcome to renaming registry entries"
write-host "Before renaming"
Get-ItemProperty -Path  HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion
Write-Host "Renaming Pspath"
Rename-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion -Name PSPath -NewName PSP
Write-Host "Renaming PSParentPath"
Rename-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion -Name PSParentPath -NewNamePSPa
Write-Host "Renaming PSChildName"
Rename-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion -Name PSChildName -NewName PSC
Write-Host "Renaming PSProvider"
Rename-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion -Name PSProvider -NewNamePSPr
Write-Host "After Renaming"
Get-ItemProperty -Path  HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion

Output:

Renaming entries

Deleting Multiple Entries from the registry

Code:

write-host "Welcome to delting registry entries"
write-host "Before deleting the entries are"
Get-ItemProperty -Path  HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion
Write-Host "Deleting Pspath"
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion -Name PsPath
Write-Host "PSPath Entry deleted"
Write-Host "Deleting PSParentPath"
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion -Name PSParentPath
Write-Host "PSParentPath entry deleted"
Write-Host "Deleting PSChildName"
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion -Name PSChildName
Write-Host "PSChildName entry deleted"
Write-Host "Deleting PSProvider"
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion -Name PSProvider
Write-Host "PSProvider entry deleted"
Write-Host "Deleting PSDrive"
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion -Name PSDrive
Write-Host "PSDrive entry deleted"
Write-Host "Current Values"
Get-ItemProperty -Path  HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion

Output:

Deleting Multiple Entries

Creating multiple keys in the registry

Code:

Write-Host "Creating new keys in registry"
Write-Host "Creating test1 key"
New-Item -Path HKCU:\test1
Write-Host "Test1 key is created"
Write-Host "Creating test2 key"
New-Item -Path HKCU:\test2
Write-Host "Test2 key is created"
Write-Host "Creating test3 key"
New-Item -Path HKCU:\test3
Write-Host "Test3 key is created"
Write-Host "Creating test4 key"
New-Item -Path HKCU:\test4
Write-Host "Test4 key is created"
Write-Host "Creating test5 key"
New-Item -Path HKCU:\test5
Write-Host "Test5 key is created"
Write-Host "The current keys in the registry are"
Get-ChildItem -Path HKCU:\ | Select-Object Name

Output:

multiple keys

Conclusion

Thus, the article covered in detail about how PowerShell can be used to work with the registry. It demonstrated with an example of how new keys are created, deleted and values are changed. It also showed how to add registry entries to keys, how a registry key value can be changed and deleted. All the operations are illustrated with an appropriate example. To learn more in detail it is advisable to write sample scripts and work on them. The article also demonstrated bulk-adding and deletion of keys and bulk addition and deletion of entries to the keys. The more the practice is done, the more the learning can be.

Recommended Articles

This is a guide to PowerShell Registry. Here we discuss introduction to PowerShell Registry, syntax, creating keys, deleting multiple keys, and entries. You can also go through our other related articles to learn more –

  1. PowerShell Rename Folder
  2. PowerShell Get-Location
  3. PowerShell Set-Location
  4. PowerShell Commands
Popular Course in this category
PowerShell Training (2 Courses, 1 Project)
  2 Online Courses |  1 Hands-on Project |   4+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Shell Scripting Training (4 Courses, 1 Project)4.9
All in One Data Science Bundle (360+ Courses, 50+ projects)4.8
Data Visualization Training (15 Courses, 5+ Projects)4.7
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more