PowerShell/Registry - Wikiversity (2024)

PowerShell
  1. Introduction
  2. Console
  3. ISE
  4. Variables
  5. Expressions
  6. Conditions
  7. Loops
  8. Arrays and Hash Tables
  9. Functions
  10. Errors
  11. File System
  12. Registry
  13. Systems Management
  14. Event Logs
  15. Additional Topics
Download Learning Guide

This lesson introduces PowerShell Registry processing.

Contents

  • 1 Objectives and Skills
  • 2 Readings
  • 3 Multimedia
  • 4 Examples
    • 4.1 Get-PSDrive
    • 4.2 New-Item
    • 4.3 New-ItemProperty
    • 4.4 Get-Item
    • 4.5 Get-ItemProperty
    • 4.6 Set-ItemProperty
    • 4.7 Remove-Item
    • 4.8 Remove-ItemProperty
  • 5 Activities
  • 6 Lesson Summary
  • 7 Key Terms
  • 8 Review Questions
  • 9 Assessments
  • 10 See Also
  • 11 References

Objectives and Skills

[edit | edit source]

After completing this lesson, you will be able to:

  • Describe basic PowerShell Windows Registry concepts.
  • Create PowerShell scripts to manage Registry keys.

Readings

[edit | edit source]

  1. Wikipedia: Windows Registry
  2. Wikipedia: INI file
  3. BonusBits: Mastering PowerShell Chapter 16 - The Registry

[edit | edit source]

  1. YouTube: Working With Registry Items In Powershell
  2. YouTube: Windows PowerShell - How To - Windows Registry

Examples

[edit | edit source]

Get-PSDrive

[edit | edit source]

The Get-PSDrive cmdlet gets the drives available in the current session, including logical mapped network drives and drives exposed by Windows PowerShell providers.[1]

Get-PSDrive -PSProvider Registry

Example output:

PS C:\Windows\system32> Get-PSDriveName Used (GB) Free (GB) Provider Root CurrentLocation---- --------- --------- -------- ---- ---------------Alias AliasC 56.04 408.13 FileSystem C:\ Windows\system32Cert Certificate \D FileSystem D:\Env EnvironmentFunction FunctionHKCU Registry HKEY_CURRENT_USERHKLM Registry HKEY_LOCAL_MACHINEVariable VariableWSMan WSMan

New-Item

[edit | edit source]

The New-Item cmdlet creates a new item and sets its value.[2]

$path = 'HKCU:\Software\Scripts'if(!(Test-Path -Path $path)){ New-Item -Path $path}$path = 'HKCU:\Software\Scripts\My Script'if(!(Test-Path -Path $path)){ New-Item -Path $path}

New-ItemProperty

[edit | edit source]

The New-ItemProperty cmdlet creates a new property for an item and sets its value.[3]

$path = 'HKCU:\Software\Scripts\My Script'$name = 'RunCount'New-ItemProperty -Path $path -Name $name -PropertyType DWord -Value 0

Get-Item

[edit | edit source]

The Get-Item cmdlet gets the item at the specified location.[4]

$path = 'HKCU:\Software\Scripts\My Script'$key = Get-Item -Path $pathforeach($name in $key.Property){ $property = Get-ItemProperty -Path $path -Name $name Write-Output ($name + ' = ' + $property.$name)}

Get-ItemProperty

[edit | edit source]

The Get-ItemProperty cmdlet gets the properties of a specified item.[5]

$path = 'HKCU:\Software\Scripts\My Script'try{ $name = 'RunCount' $key = Get-ItemProperty -Path $path -Name $name -ErrorAction Stop $runs = $key.RunCount}catch{ $runs = 0}

Set-ItemProperty

[edit | edit source]

The Set-ItemProperty cmdlet changes the value of the property of the specified item.[6]

$path = 'HKCU:\Software\Scripts\My Script'$name = 'RunCount'$runs++Set-ItemProperty -Path $path -Name $name -Value $runs

The Remove-Item cmdlet deletes one or more items.[7]

$path = 'HKCU:\Software\Scripts\My Script'Remove-Item -Path $path -Confirm

Remove-ItemProperty

[edit | edit source]

The Remove-ItemProperty cmdlet deletes a property and its value from an item.[8]

$path = 'HKCU:\Software\Scripts\My Script'$name = 'RunCount'Remove-ItemProperty -Path $path -Name $name -Confirm

Activities

[edit | edit source]

  1. Review Microsoft TechNet: Use PowerShell to Back Up System State Prior to Making Changes. Use the Checkpoint-Computer cmdlet to create a system restore point.
  2. Review Microsoft TechNet: Using the Get-PSDrive Cmdlet. Use the Get-PSDrive cmdlet to display available drives. Identify the drive names supported by the Registry provider. Use a foreach loop and the Get-ChildItem (alias Dir) cmdlet to display the root keys available in the registry drives.
  3. Review PowerShell.com: The Registry. Create a script that uses a foreach loop to display all Registry entries that contain the word 'PowerShell' in the key or the value.
  4. Review CrucialSecurityBlog: Typed URLs. Create a script that uses a foreach loop to display Internet Explorer history (Internet Explorer Typed Urls).
  5. Review Microsoft MSDN: Run and RunOnce Registry Keys. Create a script to add a RunOnce item to automatically run either PowerShell or PowerShell ISE (your choice) at the next logon.
  6. Review AskVG.com: How to Enable “Open Command Window Here” Option in Context Menu in Windows Vista and 7. Create a script to delete the 'Extended' item property from the following keys. Be sure to use the -Confirm option and carefully confirm that only the Extended property will be removed. Use Windows Explorer to confirm that 'Open command window here' now appears on the context menu without holding down the Shift key.
    • HKLM:\SOFTWARE\Classes\Directory\shell\cmd
    • HKLM:\SOFTWARE\Classes\Drive\shell\cmd

Lesson Summary

[edit | edit source]

  • The Windows Registry is a hierarchical database that stores configuration settings and options on Microsoft Windows operating systems.[9]
  • The Registry supports strongly-typed data values, while INI files are text only.[10]
  • Regedit.exe is the built-in Windows Registry editor.[11]
  • The Registry contains two basic elements: keys and values. Registry keys are container objects similar to folders. Registry values are non-container objects similar to files. Keys may contain values or further keys.[12]
  • Keys are referenced with a syntax similar to Windows' path names, using backslashes to indicate levels of hierarchy. Keys must have a case insensitive name without backslashes.[13]
  • The keys at the root level of the hierarchical database are generally named by their Windows API definitions, which all begin "HKEY".[14]
  • HKEY_LOCAL_MACHINE, abbreviated as HKLM, stores settings that are specific to the local computer.[15]
  • HKEY_CURRENT_USER abbreviated HKCU, stores settings that are specific to the currently logged-in user[16]
  • The INI file format is a simple text file with a basic structure composed of sections, properties, and values used primarily in MS-DOS and 16-bit versions of Windows.[17]
  • Windows NT and later versions of Windows use the Registry for configuration settings.[18]
  • Applications built on the .NET Framework and portable applications often use XML-format configuration files rather than the Registry.[19]
  • The PowerShell Registry provider exposes two registry paths: HKLM for HKEY_LOCAL_MACHINE and HKCU for HKEY_CURRENT_USER.[20]
  • The Get-PSDrive cmdlet gets the drives available in the current session, including logical mapped network drives and drives exposed by Windows PowerShell providers.[21]
  • The New-Item cmdlet creates a new item and sets its value.[22]
  • The New-ItemProperty cmdlet creates a new property for an item and sets its value.[23]
  • The Get-Item cmdlet gets the item at the specified location.[24]
  • The Get-ItemProperty cmdlet gets the properties of a specified item.[25]
  • The Set-ItemProperty cmdlet changes the value of the property of the specified item.[26]
  • The Remove-Item cmdlet deletes one or more items.[27]
  • The Remove-ItemProperty cmdlet deletes a property and its value from an item.[28]

Key Terms

[edit | edit source]

hive
A logical group of keys, subkeys, and values in the Registry that has a set of supporting files containing backups of its data.[29]

Review Questions

[edit | edit source]

Enable JavaScript to hide answers.

Click on a question to see the answer.

1.The Windows Registry is _____.

The Windows Registry is a hierarchical database that stores configuration settings and options on Microsoft Windows operating systems.

1.The Registry supports _____ data values, while INI files are _____.

The Registry supports strongly-typed data values, while INI files are text only.

1.Regedit.exe is _____.

Regedit.exe is the built-in Windows Registry editor.

2.The Registry contains two basic elements: _____ and _____.

The Registry contains two basic elements: keys and values.

3.Registry keys are container objects similar to _____. Registry values are non-container objects similar to _____. Keys may contain _____.

The Registry contains two basic elements: keys and values. Registry keys are container objects similar to folders. Registry values are non-container objects similar to files. Keys may contain values or further keys.

4.Keys are referenced with a syntax similar to Windows' path names, using _____. Keys must have _____.

Keys are referenced with a syntax similar to Windows' path names, using backslashes to indicate levels of hierarchy. Keys must have a case insensitive name without backslashes.

5.The keys at the root level of the hierarchical database are generally named by their Windows API definitions, which all begin _____.

The keys at the root level of the hierarchical database are generally named by their Windows API definitions, which all begin "HKEY".

6.HKEY_LOCAL_MACHINE, abbreviated as HKLM, stores _____.

HKEY_LOCAL_MACHINE, abbreviated as HKLM, stores settings that are specific to the local computer.

7.HKEY_CURRENT_USER abbreviated HKCU, stores _____.

HKEY_CURRENT_USER abbreviated HKCU, stores settings that are specific to the currently logged-in user.

8.The INI file format is _____ used primarily in _____.

The INI file format is a simple text file with a basic structure composed of sections, properties, and values used primarily in MS-DOS and 16-bit versions of Windows.

9.Windows NT and later versions of Windows use _____ for configuration settings.

Windows NT and later versions of Windows use the Registry for configuration settings.

10.Applications built on the .NET Framework and portable applications often use _____ rather than the Registry.

Applications built on the .NET Framework and portable applications often use XML-format configuration files rather than the Registry.

11.The PowerShell Registry provider _____.

The PowerShell Registry provider exposes two registry paths: HKLM for HKEY_LOCAL_MACHINE and HKCU for HKEY_CURRENT_USER.

12.The Get-PSDrive cmdlet _____.

The Get-PSDrive cmdlet gets the drives available in the current session, including logical mapped network drives and drives exposed by Windows PowerShell providers.

13.The New-Item cmdlet _____.

The New-Item cmdlet creates a new item and sets its value.

14.The New-ItemProperty cmdlet _____.

The New-ItemProperty cmdlet creates a new property for an item and sets its value.

15.The Get-Item cmdlet _____.

The Get-Item cmdlet gets the item at the specified location.

16.The Get-ItemProperty cmdlet _____.

The Get-ItemProperty cmdlet gets the properties of a specified item.

17.The Set-ItemProperty cmdlet _____.

The Set-ItemProperty cmdlet changes the value of the property of the specified item.

18.The Remove-Item cmdlet _____.

The Remove-Item cmdlet deletes one or more items.

19.The Remove-ItemProperty cmdlet _____.

The Remove-ItemProperty cmdlet deletes a property and its value from an item.

Assessments

[edit | edit source]

See Also

[edit | edit source]

References

[edit | edit source]

  1. Microsoft TechNet:Get-PSDrive
  2. Microsoft TechNet: New-Item
  3. Microsoft TechNet: New-ItemProperty
  4. Microsoft TechNet: Get-Item
  5. Microsoft TechNet: Get-ItemProperty
  6. Microsoft TechNet: Set-ItemProperty
  7. Microsoft TechNet: Remove-Item
  8. Microsoft TechNet: Remove-ItemProperty
  9. Wikipedia: Windows Registry
  10. Wikipedia: Windows Registry
  11. Wikipedia: Windows Registry
  12. Wikipedia: Windows Registry
  13. Wikipedia: Windows Registry
  14. Wikipedia: Windows Registry
  15. Wikipedia: Windows Registry
  16. Wikipedia: Windows Registry
  17. Wikipedia: INI file
  18. Wikipedia: INI file
  19. Wikipedia: INI file
  20. Microsoft TechNet: Using the Get-PSDrive Cmdlet
  21. http://technet.microsoft.com/en-us/library/hh849796.aspx Microsoft TechNet:Get-PSDrive]
  22. Microsoft TechNet: New-Item
  23. Microsoft TechNet: New-ItemProperty
  24. Microsoft TechNet: Get-Item
  25. Microsoft TechNet: Get-ItemProperty
  26. Microsoft TechNet: Set-ItemProperty
  27. Microsoft TechNet: Remove-Item
  28. Microsoft TechNet: Remove-ItemProperty
  29. Microsoft MSDN: Registry Hives

← File System

PowerShell

Systems Management →

PowerShell/Registry - Wikiversity (2024)
Top Articles
Use eSIM while traveling internationally with your iPhone - Apple Support (NG)
Advanced Coin Counting Technology for Enhanced Safety and Convenience  - Coinstar for Retail
WALB Locker Room Report Week 5 2024
Skylar Vox Bra Size
Dannys U Pull - Self-Service Automotive Recycling
jazmen00 x & jazmen00 mega| Discover
Free Atm For Emerald Card Near Me
Georgia Vehicle Registration Fees Calculator
Bloxburg Image Ids
Shooting Games Multiplayer Unblocked
Best Fare Finder Avanti
Wisconsin Women's Volleyball Team Leaked Pictures
Missing 2023 Showtimes Near Landmark Cinemas Peoria
The ULTIMATE 2023 Sedona Vortex Guide
Paychex Pricing And Fees (2024 Guide)
Aspen Mobile Login Help
All Obituaries | Buie's Funeral Home | Raeford NC funeral home and cremation
Saatva Memory Foam Hybrid mattress review 2024
Lowes Undermount Kitchen Sinks
Mini Handy 2024: Die besten Mini Smartphones | Purdroid.de
Cb2 South Coast Plaza
10 Best Places to Go and Things to Know for a Trip to the Hickory M...
Receptionist Position Near Me
Pacman Video Guatemala
Studentvue Calexico
Biografie - Geertjan Lassche
Hwy 57 Nursery Michie Tn
Orange Park Dog Racing Results
4.231 Rounded To The Nearest Hundred
Airg Com Chat
FREE Houses! All You Have to Do Is Move Them. - CIRCA Old Houses
Helloid Worthington Login
Springfield.craigslist
Salons Open Near Me Today
The Land Book 9 Release Date 2023
#1 | Rottweiler Puppies For Sale In New York | Uptown
Wsbtv Fish And Game Report
Otter Bustr
Craigslist Gigs Wichita Ks
Boone County Sheriff 700 Report
Koninklijk Theater Tuschinski
Evil Dead Rise (2023) | Film, Trailer, Kritik
Publictributes
Lcwc 911 Live Incident List Live Status
All Obituaries | Sneath Strilchuk Funeral Services | Funeral Home Roblin Dauphin Ste Rose McCreary MB
The best specialist spirits store | Spirituosengalerie Stuttgart
Timothy Warren Cobb Obituary
Child care centers take steps to avoid COVID-19 shutdowns; some require masks for kids
Gli italiani buttano sempre più cibo, quasi 7 etti a settimana (a testa)
Hcs Smartfind
32 Easy Recipes That Start with Frozen Berries
Latest Posts
Article information

Author: Jerrold Considine

Last Updated:

Views: 5412

Rating: 4.8 / 5 (58 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Jerrold Considine

Birthday: 1993-11-03

Address: Suite 447 3463 Marybelle Circles, New Marlin, AL 20765

Phone: +5816749283868

Job: Sales Executive

Hobby: Air sports, Sand art, Electronics, LARPing, Baseball, Book restoration, Puzzles

Introduction: My name is Jerrold Considine, I am a combative, cheerful, encouraging, happy, enthusiastic, funny, kind person who loves writing and wants to share my knowledge and understanding with you.