powershell獲取環(huán)境變量的方法

字號(hào):


    這篇文章主要介紹了powershell獲取環(huán)境變量的方法,同時(shí)介紹了一個(gè)列出包含某關(guān)鍵字的環(huán)境變量的方法,需要的朋友可以參考下。
    powershell中獲取一個(gè)windows環(huán)境變量,簡(jiǎn)單一點(diǎn)就是使用“env:”前綴:
    代碼如下:
    ps>$env:windir
    c:\windows
    ps>$env:username
    tobias
    實(shí)際上“env:”是一種驅(qū)動(dòng),所以你能查詢到大多或部分環(huán)境變量。下面將顯示全部的名字中包含user的環(huán)境變量:
    代碼如下:
    ps>direnv:\*user*
    namevalue
    ---------
    userprofilec:\users\tobias
    usernametobias
    allusersprofilec:\programdata
    userdomaintobiasair1