Public/Remove-EnvironmentVariable.ps1

function Remove-EnvironmentVariable {
  [CmdletBinding()]
  Param (
    [Parameter (
      Position    = 1,
      Mandatory   = $true,
      HelpMessage = "Name of the environment variable"
    )]
    [ValidateNotNullOrEmpty()]
    [Alias ("Variable")]
    [String]
    $Name,
    [Parameter (
      Position    = 2,
      Mandatory   = $false,
      HelpMessage = "Scope of the environment variable"
    )]
    [ValidateSet ("Machine", "Process", "User")]
    [String]
    $Scope = "Machine"
  )
  Begin {
    # Get global preference variables
    Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState
  }
  Process {
    # Check if variable is defined
    if (Test-EnvironmentVariable -Variable $Name -Scope $Scope) {
      Write-Log -Type "INFO" -Message "Removing $Name environment variable in $Scope scope"
      [Environment]::SetEnvironmentVariable($Name, "", $Scope)
    } else {
      Write-Log -Type "WARN" -Message "$Name environment variable is not defined in $Scope scope"
    }
  }
}