I am trying to write a PSscript that would return all registry keys and subkeys. I can return all the values under a registry key using the line below but I don't know how to recursively look into each subkey.
Get-ChildItem -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Dell\*
Any help is appreciated. I am positive someone must have done this before but I can't seem to find anything.
Whether you are listing file / folder information or registry, the Get-ChildItem cmdlet has a -recuse switch, as shown / detailed in the help files, for getting all data in a path.
The Get-ChildItem cmdlet gets the items in one or more specified locations. If the item is a container, it gets the items inside the container, known as child items. You can use the Recurse parameter to get items in all child containers and use the Depth parameter to limit the number of levels to recurse.
Get-ChildItem does not display empty directories. When a Get-ChildItem command includes the Depth or Recurse parameters, empty directories are not included in the output.
Locations are exposed to Get-ChildItem by PowerShell providers. A location can be a file system directory, registry hive, or a certificate store. For more information, see about_Providers.
This is basic Powershell 100 level stuff, and if you are new to PS, that's cool and all, but please do yourself a favor and spend a few hours on YouTube learning PowerShell before really diving into it. As well as all the other free / no cost training on this forum (see the links provided) as well as all over the web.
It is vital you spend the time getting up to speed on it as to limit / avoid, misconceptions, bad habits, bad code, errors, confusion or seriously damaging your environment.
Note: you can get at the other registry specifics using the Get-Item and Get-ItemProperty cmdlets as well.
Windows PowerShell Survival Guide
Purpose of this Document The purpose of this document is to help you to learn more about PowerShell and to be successful in applying it. This document seeks to point to the best content on the web to enable you to reach that goal.
Scope of this DocumentThis page contains links to help you learn more about Microsoft Windows PowerShell. This includes PowerShell fundamentals as well as how PowerShell is used in Windows applications and services. As long as it's PowerShell related, we'll try to point to it! The document is also version agnostic, and contains information about current and future versions of PowerShell.
See also posts here for other resource suggestions here:
Learning this stuff.https://www.reddit.com/r/PowerShell/comments/bserj9/learn_powershell/eooduq9/?context=3 https://www.reddit.com/r/PowerShell/comments/bserj9/learn_powershell/eoodxzu/?context=3
Practice with PSKoans
PSKoans : 0.50.0 A module designed to provide a crash-course introduction to PowerShell with programming koans.https://www.powershellgallery.com/packages/PSKoans/0.50.0
Come to know your dev tools / environments:Built into Windows PowerShell ISE (though no more work is going into it, Micros has already said, it will always be in the OS).
Visual Studio Code, then new hotness, for developers, and scripters. It takes a while to get it configure for all you will need, and provides far more that the ISE does.
Sapien's PowerShell studio is the first class / top tier full IDE for PowerShell, but it not a inexpensive one, but well worth the price IMHO.https://www.sapien.com/software/powershell_studio
Learn to use both, as in most cases, data center servers will not have VSCode, but the ISE is in the box.
There are a bunch of add-one / extensions for both.
Then of course you can use full Visual Studio for PowerShell script, GUI, module development. As you can with VSCode, just be sure to purchase the full PowerShell Pro Tools addon for PowerShell project. It's $59.00, so, in expensive, though to continue to get updates for it, that is an annual cost.