Windows user environment variable vs. system environment variable

后端 未结 2 1231
醉梦人生
醉梦人生 2021-02-05 13:29

In Windows, is there any shell/PowerShell command to list user environment variable and system environment variable separately?

If I do -

SET TEMP
         


        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-05 13:43

    In PowerShell, there's no cmdlet for it, but you can use the underlying .NET methods in the Environment class:

    Write-Host "Machine environment variables"
    [Environment]::GetEnvironmentVariables("Machine")
    
    Write-Host "User environment variables"
    [Environment]::GetEnvironmentVariables("User")
    
    # This should be the same as 'Get-ChildItem env:', although it isn't sorted.
    Write-Host "Process environment variables"
    [Environment]::GetEnvironmentVariables("Process")
    

提交回复
热议问题