Source/Environment/Set-EnvironmentVariable.ps1

<#
.SYNOPSIS
    Sets the value of an environment variable.
.DESCRIPTION
    Wraps [Environment]::SetEnvironmentVariable to write an environment variable to a specific scope.
.PARAMETER Name
    The name of the environment variable.
.PARAMETER Value
    The value to assign to the environment variable.
.PARAMETER Scope
    The scope to write the variable to: Process, User, or Machine. Defaults to Process.
.EXAMPLE
    Set-EnvironmentVariable -Name "Foo" -Value "Bar" -Scope "User"
.EXAMPLE
    [pscustomobject]@{ Name = "Foo"; Value = "Bar" } | Set-EnvironmentVariable -Scope "User"
.INPUTS
    [System.Management.Automation.PSObject] Accepts objects with Name and Value properties via pipeline by property name.
.OUTPUTS
    None.
#>


function Set-EnvironmentVariable {

    [CmdletBinding(SupportsShouldProcess)]

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

        [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
        [string]
        $Value,

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

    process {

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

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

        }

    }

}