Skip to content

Latest commit

 

History

History
109 lines (95 loc) · 4.8 KB

File metadata and controls

109 lines (95 loc) · 4.8 KB

Get-OZORegistryKey

This function is part of the OZORegistry PowerShell Module.

Description

Returns an OZORegistryKey object. This object may represent a new or existing registry key. The object contains methods for reading, adding, updating, and removing key names; and methods for displaying the key and--once all desired changes have been staged--for processing the changes to the key. This function (and resulting object) provide the most robust and flexible use of this module.

Syntax

Get-OZORegistryKey
    -Key     <String>
    -Display <Switch>

Parameters

Parameter Description
Key The registry key in the short (HKLM:\...) or long (HKEY_LOCAL_MACHINE\...) format. Key may be new or existing.
Display Display console messages (effective only for user-interactive sessions).

Examples

Example 1

Return an object representing a registry key with console messages.

$ozoRegistryKey = (Get-OZORegistryKey -Key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion" -Display)
Using key path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion.
Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion exists and all values read.

Name                     Type         Value
----                     ----         ----
ProgramFilesDir          String       C:\Program Files
CommonFilesDir           String       C:\Program Files\Common Files
ProgramFilesDir (x86)    String       C:\Program Files (x86)
CommonFilesDir (x86)     String       C:\Program Files (x86)\Common Files
CommonW6432Dir           String       C:\Program Files\Common Files
DevicePath               ExpandString %SystemRoot%\inf
MediaPathUnexpanded      ExpandString %SystemRoot%\Media
ProgramFilesPath         ExpandString %ProgramFiles%
ProgramW6432Dir          String       C:\Program Files

Example 2

Return an object representing a registry key without console messages.

$ozoRegistryKey = (Get-OZORegistryKey -Key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion")

Example 3

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.

$ozoRegistryKey = (Get-OZORegistryKey -Key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion")
$ozoRegistryKey.DisplayKeyValues()
$ozoRegistryKey.SetDisplay($true)
$ozoRegistryKey.DisplayKeyValues()

Name                     Type         Value
----                     ----         ----
ProgramFilesDir          String       C:\Program Files
CommonFilesDir           String       C:\Program Files\Common Files
ProgramFilesDir (x86)    String       C:\Program Files (x86)
CommonFilesDir (x86)     String       C:\Program Files (x86)\Common Files
CommonW6432Dir           String       C:\Program Files\Common Files
DevicePath               ExpandString %SystemRoot%\inf
MediaPathUnexpanded      ExpandString %SystemRoot%\Media
ProgramFilesPath         ExpandString %ProgramFiles%
ProgramW6432Dir          String       C:\Program Files

Example 4

Get the value and the type for the ProgramFilesDir name.

$ozoRegistryKey = (Get-OZORegistryKey -Key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion")
$ozoRegistryKey.ReturnKeyNameValue("ProgramFilesDir")
C:\Program Files
$ozoRegistryKey.ReturnKeyNameType("ProgramFilesDIr")
String

Example 5

Get add a new name to an existing registry key.

$ozoRegistryKey = (Get-OZORegistryKey -Key "HKEY_LOCAL_MACHINE\SOFTWARE\One Zero One")
If (($ozoRegistryKey.AddKeyName("Version","1.0.0")) -eq $true) {
    $ozoRegistryKey.ProcessChanges()
}

Example 6

Update an existing registry key name with a new value.

$ozoRegistryKey = (Get-OZORegistryKey -Key "HKEY_LOCAL_MACHINE\SOFTWARE\One Zero One")
If (($ozoRegistryKey.UpdateKeyName("Version","2.0.0")) -eq $true) {
    $ozoRegistryKey.ProcessChanges()
}

Example 7

Remove an existing name from a registry key

$ozoRegistryKey = (Get-OZORegistryKey -Key "HKEY_LOCAL_MACHINE\SOFTWARE\One Zero One")
If (($ozoRegistryKey.UpdateName("Version")) -eq $true) {
    $ozoRegistryKey.ProcessChanges()
}

Logging

Messages as written to the Windows Event Viewer One Zero One provider when available. Otherwise, messages are written to the Microsoft-Windows-PowerShell provider under event ID 4100.

Notes

For more information, please see the OZORegistryKey and OZORegistryKeyValue class definitions.