|
| 1 | +# Get-OZORegistryKey |
| 2 | +This function is part of the [OZORegistry PowerShell Module](../README.md). |
| 3 | + |
| 4 | +## Description |
| 5 | +Returns an `OZORegistryKey` object. This object may represent a new or existing registry key. The object contains methods for [reading, adding, updating, and removing](OZORegistryKey.md#public-methods) key names; and methods for [displaying](OZORegistryKey.md#public-methods) the key and--once all desired changes have been staged--for [processing](OZORegistryKey.md#public-methods) the changes to the key. This function (and resulting object) provide the most robust and flexible use of this module. |
| 6 | + |
| 7 | +## Syntax |
| 8 | +``` |
| 9 | +Get-OZORegistryKey |
| 10 | + -Key <String> |
| 11 | + -Display <Switch> |
| 12 | +``` |
| 13 | + |
| 14 | +## Parameters |
| 15 | +|Parameter|Description| |
| 16 | +|---------|-----------| |
| 17 | +|`Key`|The registry key in the short (`HKLM:\...`) or long (`HKEY_LOCAL_MACHINE\...`) format. Key may be new or existing.| |
| 18 | +|`Display`|Display console messages (effective only for user-interactive sessions).| |
| 19 | + |
| 20 | +## Examples |
| 21 | +### Example 1 |
| 22 | +Return an object representing a registry key **with** console messages. |
| 23 | +```powershell |
| 24 | +$ozoRegistryKey = (Get-OZORegistryKey -Key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion" -Display) |
| 25 | +Using key path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion. |
| 26 | +Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion exists and all values read. |
| 27 | +
|
| 28 | +Name Type Value |
| 29 | +---- ---- ---- |
| 30 | +ProgramFilesDir String C:\Program Files |
| 31 | +CommonFilesDir String C:\Program Files\Common Files |
| 32 | +ProgramFilesDir (x86) String C:\Program Files (x86) |
| 33 | +CommonFilesDir (x86) String C:\Program Files (x86)\Common Files |
| 34 | +CommonW6432Dir String C:\Program Files\Common Files |
| 35 | +DevicePath ExpandString %SystemRoot%\inf |
| 36 | +MediaPathUnexpanded ExpandString %SystemRoot%\Media |
| 37 | +ProgramFilesPath ExpandString %ProgramFiles% |
| 38 | +ProgramW6432Dir String C:\Program Files |
| 39 | +``` |
| 40 | + |
| 41 | +### Example 2 |
| 42 | +Return an object representing a registry key **without** console messages. |
| 43 | +```powershell |
| 44 | +$ozoRegistryKey = (Get-OZORegistryKey -Key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion") |
| 45 | +``` |
| 46 | + |
| 47 | +### Example 3 |
| 48 | +Return an object representing a registry key **without** console messages, and set the _Display_ property to enable console messages. _Note: For clarity and brevity, the remaining examples will omit console messages._ |
| 49 | +```powershell |
| 50 | +$ozoRegistryKey = (Get-OZORegistryKey -Key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion") |
| 51 | +$ozoRegistryKey.DisplayKeyValues() |
| 52 | +$ozoRegistryKey.SetDisplay($true) |
| 53 | +$ozoRegistryKey.DisplayKeyValues() |
| 54 | +
|
| 55 | +Name Type Value |
| 56 | +---- ---- ---- |
| 57 | +ProgramFilesDir String C:\Program Files |
| 58 | +CommonFilesDir String C:\Program Files\Common Files |
| 59 | +ProgramFilesDir (x86) String C:\Program Files (x86) |
| 60 | +CommonFilesDir (x86) String C:\Program Files (x86)\Common Files |
| 61 | +CommonW6432Dir String C:\Program Files\Common Files |
| 62 | +DevicePath ExpandString %SystemRoot%\inf |
| 63 | +MediaPathUnexpanded ExpandString %SystemRoot%\Media |
| 64 | +ProgramFilesPath ExpandString %ProgramFiles% |
| 65 | +ProgramW6432Dir String C:\Program Files |
| 66 | +``` |
| 67 | + |
| 68 | +### Example 3 |
| 69 | +Get the value and the type for the _ProgramFilesDir_ name. |
| 70 | +```powershell |
| 71 | +$ozoRegistryKey = (Get-OZORegistryKey -Key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion") |
| 72 | +$ozoRegistryKey.ReturnKeyNameValue("ProgramFilesDir") |
| 73 | +C:\Program Files |
| 74 | +$ozoRegistryKey.ReturnKeyNameType("ProgramFilesDIr") |
| 75 | +String |
| 76 | +``` |
| 77 | + |
| 78 | +### Example 4 |
| 79 | +Get add a new name to an existing registry key. |
| 80 | +```powershell |
| 81 | +$ozoRegistryKey = (Get-OZORegistryKey -Key "HKEY_LOCAL_MACHINE\SOFTWARE\One Zero One") |
| 82 | +If (($ozoRegistryKey.AddKeyName("Version","1.0.0")) -eq $true) { |
| 83 | + $ozoRegistryKey.ProcessChanges() |
| 84 | +} |
| 85 | +``` |
| 86 | + |
| 87 | +### Example 5 |
| 88 | +Update an existing registry key name with a new value. |
| 89 | +```powershell |
| 90 | +$ozoRegistryKey = (Get-OZORegistryKey -Key "HKEY_LOCAL_MACHINE\SOFTWARE\One Zero One") |
| 91 | +If (($ozoRegistryKey.UpdateKeyName("Version","2.0.0")) -eq $true) { |
| 92 | + $ozoRegistryKey.ProcessChanges() |
| 93 | +} |
| 94 | +``` |
| 95 | + |
| 96 | +### Example 6 |
| 97 | +Remove an existing name from a registry key |
| 98 | +```powershell |
| 99 | +$ozoRegistryKey = (Get-OZORegistryKey -Key "HKEY_LOCAL_MACHINE\SOFTWARE\One Zero One") |
| 100 | +If (($ozoRegistryKey.UpdateName("Version")) -eq $true) { |
| 101 | + $ozoRegistryKey.ProcessChanges() |
| 102 | +} |
| 103 | +``` |
| 104 | + |
| 105 | +## Logging |
| 106 | +Messages as written to the Windows Event Viewer [_One Zero One_](https://github.com/onezeroone-dev/OZOLogger-PowerShell-Module/blob/main/README.md) provider when available. Otherwise, messages are written to the _Microsoft-Windows-PowerShell_ provider under event ID 4100. |
| 107 | + |
| 108 | +## Notes |
| 109 | +For more information, please see the [`OZORegistryKey`](OZORegistryKey.md) and [`OZORegistryKeyValue`](OZORegistryKeyValue.md) class definitions. |
0 commit comments