Use the following function to set persistent system environment variables.
function Set-PersistentEnviromentVariable ($Name, $Value)
{
$Name = $Name -replace '"','\"'
$Value = $Value -replace '"','\"'

$null = setx.exe """$Name""" """$Value"""
if ($LASTEXITCODE -ne 0)
{
Write-Error -Message "Setting environment variable failed with errorcode $LASTEXITCODE"
}
}
Set-PersistentEnviromentVariable -Name YOURNAME -Value YOURVALUE