Public/New-specRegistryObject.ps1

function New-specRegistryObject {
    <#
    .SYNOPSIS
        Creates a new instance of the Registry object for interacting with the Windows Registry.
 
    .DESCRIPTION
        Initialises a Registry object with the provided registry hive, key path, and optionally, value name, value data, and value type.
 
    .PARAMETER Hive
        The root registry hive (e.g., 'HKCU:', 'HKLM:').
 
    .PARAMETER KeyPath
        The relative path to the registry key within the specified hive.
 
    .PARAMETER ValueName
        (Optional) The name of the registry value.
 
    .PARAMETER ValueData
        (Optional) The data associated with the registry value.
 
    .PARAMETER ValueType
        (Optional) The type of the registry value. Default is 'String'.
 
    .OUTPUTS
        Returns a Registry object for further registry operations.
 
    .EXAMPLE
        $reg = New-specRegistryObject -Hive "HKCU:" -KeyPath "Software\MyApp"
 
        Creates a new Registry object for the specified hive and key path, without value data or type.
 
    .NOTES
        Author: owen.heaume
        Version: - 1.0 Initial version
                    - 1.1 Add new 'If' to take into account other constructors in the class
    #>


    param (
        [Parameter(Mandatory = $true)]
        [ValidateSet('HKCU:', 'HKLM:')]
        [string]$Hive,

        [Parameter(Mandatory = $true)]
        [string]$KeyPath,

        [string]$ValueName = $null,

        [string]$ValueData = $null,

        [ValidateSet('String', 'ExpandString', 'Binary', 'DWord', 'MultiString', 'QWord')]
        [string]$ValueType = 'String'
    )

    # If ValueName is not provided, assume the overload constructor is to be used
    if ($ValueName -eq $null) {
        return [specRegistry]::new($Hive, $KeyPath)
    } else {
        # Convert string value type to RegistryType enum
        $RegistryType = [RegistryType]::$ValueType
        return [specRegistry]::new($Hive, $KeyPath, $ValueName, $ValueData, $RegistryType)
    }
}