[英]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.