# encoding: ascii
# api: powershell
# title: Set-EnvironmentVariable
# description: Allows you to easily create machine-level environment variables that will persist after reboots.  Note that the variables created this way may not be visible in the variable: or even env: providers until you restart your Powershell session.  Allowable values to Target param are “process”, “user”, and “machine”.
# version: 0.1
# type: function
# author: halr9000
# license: CC0
# function: Set-EnvironmentVariable
# x-poshcode-id: 1243
# x-archived: 2012-07-30T02:42:56
# x-published: 2009-07-29T09:15:00
#
# Usage: 
# set-environmentvariable -name Test -value “test value” -target machine -passthru
# TODO: Needs v2 autohelp
#
#requires -version 2

function Set-EnvironmentVariable {
	param (
		[String] [Parameter( Position = 0, Mandatory = $true )] $Name,
		[String] [Parameter( Position = 1, Mandatory = $true )] $Value,
		[EnvironmentVariableTarget] 
			[Parameter( Position = 2 )]
			$Target = [EnvironmentVariableTarget]::Process, 
		[switch] $Passthru
	)
	[environment]::SetEnvironmentVariable( $Name, $Value, $Target )
	if ( $Passthru ) {
		$result = [environment]::GetEnvironmentVariable( $Name, $Target )
		Write-Output @{ $Name = $Result }
	}
}
