Public/Remove-SpecEnvironmentVariable.ps1

Function Remove-SpecEnvironmentVariable {

    [CmdletBinding()]

    param (
        [Parameter(Mandatory = $true)]
        [AllowNull()]
        [AllowEmptyString()]
        [string]$VariableName,

        [validateset ("User", "Machine", "Process") ]
        [string]$scope
    )

    try {
        write-verbose "Adding [$VariableName] with a value of [$VariableValue] at the machine level"
        [System.Environment]::SetEnvironmentVariable($VariableName, $NULL, [System.EnvironmentVariableTarget]::$scope)
        write-verbose "Removing at scope: $scope"
        return 0
    } catch {
        Write-Warning "An error occurred while setting the machine level environment variable: $_"
        return 2
    }
}