[英]Access a specific user environment variable on windows server
有沒有一種方法可以使用Powershell訪問特定的用戶環境變量?
在服務器計算機上,我們有50個用戶。 我想知道特定用戶(例如user1
是否為環境變量PYTH_HOME_LOG
使用其他值。
該系統變量指向C:\\PYTHON\\LOG
,我想檢查哪個用戶通過配置用戶環境變量PYTH_HOME_LOG
更改此位置。
如果您是本地Administrators組的成員,則只需遍歷所有用戶注冊表配置單元並在其中搜索Environment
變量:
$AllUserHives = Get-ChildItem Registry::HKEY_USERS\ |Where Name -like "HKEY_USERS\S-1-5-21*[0-9]"
foreach($UserHive in $AllUserHives){
if(Get-ItemProperty -Path "$UserHive\Environment" -Name PYTH_HOME_LOG -EA SilentlyContinue){
# User is overriding %PYTH_HOME_LOG%
}
}
您可以通過搜索USERNAME
env變量從Volatile Environment
注冊表子樹中獲取相應的用戶名,也可以使用IdentityReference.Translate()
:
$SID = [System.Security.Principal.SecurityIdentifier]"S-1-5-21-436246-18267386-368368356-356777"
$Username = $SID.Translate([System.Security.Principal.NTAccount]).Value
或者,在這種情況下:
$SID = ($UserHive -split '\\')[-1] -as [System.Security.Principal.SecurityIdentifier]
$Username = $SID.Translate([System.Security.Principal.NTAccount]).Value
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.