2015年(5)
分类: 系统运维
2015-06-26 21:36:19
#创建环境变量
Function Create-EnvironmentVariable
{
param
(
[Parameter(Mandatory=$true)]
$Name,
$Value,
[System.EnvironmentVariableTarget]
$Target
)
[System.Environment]::SetEnvironmentVariable($Name, $Value, $Target )
}
#在现有的环境变量后添加值
Function Add-EnvironmentVariable
{
param
(
[Parameter(Mandatory=$true)]
$Name,
$Value,
[System.EnvironmentVariableTarget]
$Target
)
$OldValue = [environment]::GetEnvironmentVariable($Name,[System.EnvironmentVariableTarget]::Machine)
[Environment]::SetEnvironmentVariable( $Name, $OldValue+$Value, [System.EnvironmentVariableTarget]::Machine )
}
Set-EnvironmentVariable -Name "JAVA_HOME" -Value "C:\Program Files\Java\jdk1.8.0_45" -Target Machine
Set-EnvironmentVariable -Name "CLASSPATH" -Value ".;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar" -Target Machine
Add-EnvironmentVariable -Name "Path" -Value ";%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;"-Target Machine