Skip to content

Commit f1ddd70

Browse files
alievertzAndy Lievertz
andauthored
Initial release including several functions and classes; v1.0.0
* Initial release including several functions and classes; v1.0.0 --------- Co-authored-by: Andy Lievertz <[email protected]>
1 parent 2dc44a7 commit f1ddd70

14 files changed

+1196
-36
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
temp.ps1
2+
registrykeyvalueclass.ps1

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# OZORegistry PowerShell Module Change Log
2+
3+
|Date|Version|Comment|
4+
|----|-------|-------|
5+
|2025-Jun-01|1.0.0|Initial release including `Convert-OZORegistryString`,`Get-OZORegistryKey`,`Read-OZORegistryKeyNameValue`,`Read-OZORegistryKeyNameType`,and `Write-OZORegistryKeyNameValue`.|
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Convert-OZORegistryPath
2+
This function is part of the [OZORegistry PowerShell Module](../README.md).
3+
4+
## Description
5+
Converts a registry string from one format to another, e.g., _HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion_ to _HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion_. If the input string is invalid, it is returned unmodified.
6+
7+
## Syntax
8+
```
9+
Convert-OZORegistryPath
10+
-RegistryPath <String>
11+
```
12+
13+
## Parameters
14+
|Parameter|Description|
15+
|---------|-----------|
16+
|`RegistryPath`|The registry string to convert. Accepts pipeline input.|
17+
18+
## Examples
19+
### Example 1
20+
```powershell
21+
Convert-OZORegistryPath -Path "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion"
22+
HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion
23+
```
24+
### Example 2
25+
```powershell
26+
Convert-OZORegistryPath -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion"
27+
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion
28+
```
29+
### Example 3
30+
```powershell
31+
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion" | Convert-OZORegistryPath
32+
HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion
33+
```
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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.

Documentation/OZORegistryKey.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# OZORegistryKey Class
2+
This class is part of the [OZORegistry PowerShell Module](../README.md).
3+
4+
## Usage
5+
Use [`Get-OZORegistryKey`](Get-OZORegistryKey.md) function to return an object of this class.
6+
7+
## Public Properties
8+
|Property|Type|Description|
9+
|--------|----|-----------|
10+
|`Display`|Boolean|Determines whether or not console messages are displayed during a user-interactive session. See `SetDisplay()`.|
11+
|`keyExists`|Boolean|True if the key Exists and otherwise False. This can be used to determine if the object represents an existing key (True) or a new key (False).|
12+
|`keyPathValid`|Boolean|True if the key format is valid and otherwise False. This limits whether a key can be read or written.|
13+
|`namesRead`|Boolean|True if the key exists and all values were successfully read.|
14+
|`keyPath`|String|The registry key path, parsed for use with PowerShell cmdlets.|
15+
16+
## Public Methods
17+
|Method|Return Type|Description|
18+
|------|-----------|-----------|
19+
|`SetDisplay([Boolean]$DisplayBool)`|Void|Sets the `$Display` property. Requires `$true` or `$false` and sets the `$Display` boolean accordingly.|
20+
|`DisplayKey()`|Void|Displays the contents of the `$Names` array that represents `$Key`. Only produces output when `$Display` is `$true` and the session is user-interactive. Use `SetDisplay()` to set `$Display`.|
21+
|`ReturnKeyNameValue([String]$Name,[String]$Value)`|`Byte[]`\|`Int32`\|`Int64`\|`String`\|`String[]`|Returns the value for a given name.|
22+
|`ReturnKeyNameType([String]$Name,[String]$Value)`|`String`|Returns the type for a given name.|
23+
|`AddKeyName([String]$Name,[Object]$Value)`|`Boolean`||
24+
|`RemoveKeyName([String]$Name)`|`Boolean`||
25+
|`UpdateKeyName([String]$Name,[Object]$Value)`||
26+
|`ProcessChanges()`|`Boolean`||
27+
28+
## Definition
29+
### Associations
30+
```
31+
+ $Display:Boolean = $false
32+
+ $keyExists:Boolean = $true
33+
+ $keyPathValid:Boolean = $true
34+
+ $namesRead:Boolean = $true
35+
+ $keyPath:String = $null
36+
- $Key:PSCustomObject = $null
37+
- $Logger:PSCustomObject = $null
38+
- $Names:System.Collections.Generic.List[PSCustomObject] = @()
39+
```
40+
### Operations
41+
```
42+
+ OZORegistryKey($KeyPath:String,$Display:Boolean):Void
43+
- ValidateKeyPath($KeyPath:String):Boolean
44+
- ReadKey():Boolean
45+
- ReadKeyValues():Boolean
46+
+ SetDisplay($DisplayBool:Boolean):Void
47+
+ DisplayKey():Void
48+
+ ReturnKeyNameValue($Name:String):Object
49+
+ ReturnKeyNameType($Name:String):String
50+
+ AddKeyName($Name:String,$Value):Void
51+
+ RemoveKeyName($Name:String):Void
52+
+ UpdateKeyName($Name:String,$Value):Void
53+
+ ProcessChanges():Boolean
54+
```
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# OZORegistryKeyValue Class
2+
This class is part of the [OZORegistry PowerShell Module](../README.md).
3+
4+
## Usage
5+
This class defined for internal use.
6+
7+
## Definition
8+
### Associations
9+
```
10+
+ $Name:String = $null
11+
+ $Type:String = $null
12+
```
13+
---
14+
```
15+
<<Dynamic>>
16+
+ $Data:Byte[]
17+
+ $Data:Int32
18+
+ $Data:String
19+
+ $Data:String[]
20+
+ $Data:Int64
21+
```
22+
### Operations
23+
```
24+
+ OZORegistryKeyValue($Value:String,$Data:Byte[]):Void
25+
+ OZORegistryKeyValue($Value:String,$Data:Int32):Void
26+
+ OZORegistryKeyValue($Value:String,$Data:String):Void
27+
+ OZORegistryKeyValue($Value:String,$Data:String[]):Void
28+
+ OZORegistryKeyValue($Value:String,$Data:Int64[]):Void
29+
```
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Read-OZORegistryKeyNameType
2+
This function is part of the [OZORegistry PowerShell Module](../README.md).
3+
4+
## Description
5+
A simple function for returning the _type_ of a single registry key name. Returns "Key path is not valid" if the path is not valid, "Key not found" if the path does not exist, "Could not read key names" if the key names could not be read, and "Unhandled data type" if the data cannot be returned.
6+
7+
## Syntax
8+
```
9+
Read-OZORegistryKeyNameType
10+
-Key <String>
11+
-Name <String>
12+
```
13+
14+
## Parameters
15+
|Parameter|Description|
16+
|---------|-----------|
17+
|`Key`|The registry key.|
18+
|`Name`|The key value.|
19+
20+
## Examples
21+
### Example 1
22+
```powershell
23+
Read-OZORegistryKeyNameType -Key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion" -Name "ProgramFilesDir"
24+
String
25+
```
26+
### Example 2
27+
```powershell
28+
Read-OZORegistryKeyNameType -Key "HLKM:\SOFTWARE\Microsoft\Windows\CurrentVersion" -Name "ProgramFilesDir"
29+
String
30+
```
31+
32+
## Logging
33+
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.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Read-OZORegistryKeyNameValue
2+
This function is part of the [OZORegistry PowerShell Module](../README.md).
3+
4+
## Description
5+
A simple function for returning the value for a single registry key name. Returns "Key path is not valid" if the path is not valid, "Key not found" if the path does not exist, "Could not read key names" if the key names could not be read, and "Unhandled data type" if the data cannot be returned.
6+
7+
## Syntax
8+
```
9+
Read-OZORegistryKeyNameValue
10+
-Key <String>
11+
-Name <String>
12+
```
13+
14+
## Parameters
15+
|Parameter|Description|
16+
|---------|-----------|
17+
|`Key`|The registry key.|
18+
|`Name`|The key name.|
19+
20+
## Examples
21+
### Example 1
22+
```powershell
23+
Read-OZORegistryKeyNameValue -Key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion" -Name "ProgramFilesDir"
24+
C:\Program Files
25+
```
26+
### Example 2
27+
```powershell
28+
Read-OZORegistryKeyNameValue -Key "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion" -Name "ProgramFilesDir"
29+
C:\Program Files
30+
```
31+
32+
## Outputs
33+
`Byte[]` | `Int32` | `Int64` | `String` | `String[]`
34+
35+
## Logging
36+
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.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Write-OZORegistryKeyNameValue
2+
This function is part of the [OZORegistry PowerShell Module](../README.md).
3+
4+
## Description
5+
A simple function for adding or updating a single registry key name. If the key + name does not exist, it will be created. If it does exist, it will be updated. Returns True on success and False on failure. Failures are typically due to inadequate permissions or type mismatches.
6+
7+
## Syntax
8+
```
9+
Write-OZORegistryKeyNameValue
10+
-Key <String>
11+
-Name <String>
12+
-Value <Byte[] | Int32 | Int64 | String | String[]>
13+
-Type <String>
14+
```
15+
16+
## Parameters
17+
|Parameter|Description|
18+
|---------|-----------|
19+
|`Key`|The registry key.|
20+
|`Name`|The key name.|
21+
|`Value`|The name value.|
22+
|`Type`|The type. Valid types are `Binary`, `Dword`, `ExpandString`, `MultString`, `Qword`, and `String`. Defaults to `String`.|
23+
24+
## Examples
25+
```powershell
26+
Write-OZORegistryKeyNameValue -Key "HKEY_LOCAL_MACHINE\SOFTWARE\One Zero One" -Value "Acronym" -Data "OZO" -Type "String"
27+
True
28+
```
29+
30+
## Logging
31+
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.
32+
33+
## Notes
34+
Requires _Administrator_ privileges.

0 commit comments

Comments
 (0)