# get the correct directory
$programPath = if ( (${env:ProgramFiles(x86)}).Length -eq 0) { ${env:ProgramFiles} } else { ${env:ProgramFiles(x86) } }
# create the path to add to the path variable
$pathToAdd = "$programPath\Java\jdk1.6.0_03\bin"
# get the current value for path
$currentPath=(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).Path
# create the new value for path
$newPath = "$currentPath;$pathToAdd"
# variant1: set the path with the registry provider
Set-ItemProperty -Path 'Registry::HKLM\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH –Value $newPath
# variant2: set the path with the .NET framework
[Environment]::SetEnvironmentVariable
( "Path", $newPath, [System.EnvironmentVariableTarget]::Machine )