GinShell.Utilities/Public/Ensure-GsEnvironment.ps1

function Ensure-GsEnvironment {
    <#
    .SYNOPSIS
        Checks for an environment item and optionally creates it if missing.
    .PARAMETER Type
        Kind of item: Variable, Registry, File, Folder, Executable, or Module.
    .PARAMETER Name
        The item name or path to check.
    .PARAMETER SetIfMissing
        Attempt to create the item if it does not exist (not yet implemented for all types).
    .PARAMETER Value
        Value to set when creating the item.
    .EXAMPLE
        Ensure-GsEnvironment -Type Module -Name 'Az'
    #>

    [CmdletBinding()]
    param (
        [Parameter(Mandatory)]
        [ValidateSet('Variable', 'Registry', 'File', 'Folder', 'Executable', 'Module')]
        [string]$Type,

        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [string]$Name,

        [switch]$SetIfMissing,

        [string]$Value
    )

    if (-not (Test-GsEnvironment -Type $Type -Name $Name)) {
        Write-GsLog -Message "$Type '$Name' not found." -Type Warning
        if ($SetIfMissing) {
            if ((-not $Value) -and ($Type -notin 'Module', 'Folder')) {
                Write-GsLog -Message "Value is required to set $Type '$Name'." -Type Error
                return $false
            }
            # TODO: Implement Set-GsEnvironment to handle creating missing environment items
            Write-GsLog -Message "Set-GsEnvironment is not yet implemented. Cannot auto-create $Type '$Name'." -Type Error
            return $false
        }
        return $false
    }
    return $true
}