Source/Environment/Remove-EnvironmentVariable.ps1

<#
.SYNOPSIS
    Removes an environment variable.
.DESCRIPTION
    Wraps [Environment]::SetEnvironmentVariable, passing $null as the value, to remove an environment variable from a specific scope.
.PARAMETER Name
    The name of the environment variable.
.PARAMETER Scope
    The scope to remove the variable from: Process, User, or Machine. Defaults to Process.
.EXAMPLE
    Remove-EnvironmentVariable -Name "Foo" -Scope "User"
.EXAMPLE
    "Foo", "Bar" | Remove-EnvironmentVariable -Scope "User"
.INPUTS
    [System.String] The variable name. Accepts pipeline input by value or by property name.
.OUTPUTS
    None.
#>


function Remove-EnvironmentVariable {

    [CmdletBinding(SupportsShouldProcess)]

    param(
        [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
        [string]
        $Name,

        [System.EnvironmentVariableTarget]
        $Scope = [System.EnvironmentVariableTarget]::"Process"
    )

    process {

        if ($PSCmdlet.ShouldProcess($Name, "Remove environment variable ($Scope)")) {

            [Environment]::SetEnvironmentVariable($Name, $null, $Scope)

        }

    }

}