可以通过为变量的值指定空字符串,使用SetEnvironmentVariable()方法删除环境变量。 例如,若要删除环境变量,请执行以下操作Foo: PowerShell复制 [Environment]::SetEnvironmentVariable('Foo','') [Environment]::GetEnvironmentVariable('Foo') Output复制 有关
[Environment]::GetEnvironmentVariable('Foo') new [Environment]::SetEnvironmentVariable('Foo','Bar') update [Environment]::SetEnvironmentVariable('Foo','Tar') delete [Environment]::SetEnvironmentVariable('Foo','') TIPS 添加内容:$Env:Path += ';C:\Tools',在 Windows 中使用 ; 而不是 :。 获...
如果环境变量已经存在,使用SetEnvironmentVariable就是修改它的值。 用法与新建环境变量完全相同。 例如,修改系统环境变量 Path,将上一个例子中JAVA_HOME路径下的bin目录添加到 Path: $path=[Environment]::GetEnvironmentVariable('Path','Machine')$newpath='%JAVA_HOME%'+'\bin;'+$path# 或者:$newpath = $E...
在原有的环境变量基础上新增,并且指定作用域(用户 or 系统 or 会话),一条命令搞定: $addPath=‘c:\add\you\path\here’; $target=‘User’ ; $path = [Environment]::GetEnvironmentVariable(‘Path’, $target); $newPath = $path + ‘;’ + $addPath; [Environment]::SetEnvironmentVariable(“Path”...
$addPath='c:\add\you\path\here';$target='User';$path= [Environment]::GetEnvironmentVariable('Path',$target);if($path-match";$"){$newPath=$path+$addPath; }else{$newPath=$path+';'+$addPath; } [Environment]::SetEnvironmentVariable('Path',$newPath,$target) ...
$env:TestVar1="This is my environment variable" 删除和更新环境变量: del env:windir 更新环境变量就直接重新赋值就好了,其实,$env:中的环境变量只是机器环境变量的一个副本,即使你更改了它,下一次重新打开时,又会恢复如初。(.NET方法更新环境变量除外) ...
PS C:\Users\cxxu\Desktop> [Environment]::GetEnvironmentVariable($PA, "Machine") -split ";" D:\repos\ThinkDSP\code D:\repos\CCSER\cxxu_serlib C:\new_path_demo D:\repos\PythonLearn\cxxu_pylib D:\repos\CCSER\SER PS C:\Users\cxxu\Desktop> [Environment]::GetEnvironmentVariable($PA,...
Get-Help <cmdlet-name> 展開資料表 Cmdlet 名稱描述 Clear-Variable 刪除變數的值。 Get-Variable 取得目前控制台中的變數。 New-Variable 建立新變數。 Remove-Variable 刪除變數及其值。 Set-Variable 變更變數的值。 另請參閱 about_Automatic_Variables about_Environment_Variables about_Preference_Variables ab...
del Variable:zero -Force #constant 不可删除 Remove-Variable c 1. 2. 3. 4. 系统变量、自动变量: $HOME Get-Help about_Automatic_variables 1. 2. 3. 查看环境变量: $env:USERNAME ls env:USER* ls env: 1. 2. 3. 添加、更改、删除 当前环境变量(当前会话有效): ...
Get-ChildItem Env: Or at least it didn’t show up until we restarted PowerShell. (Or started up a new instance of PowerShell.) However, wecouldretrieve the value of the new variable at any time by using this command: [Environment]::GetEnvironmentVariable("TestVariable","User") ...