Получение полного пути к ключу реестра из значения с powershell - PullRequest
0 голосов
/ 31 августа 2018

Итак, я знаю, какое значение я ищу, но я не знаю полного пути к этому значению, поскольку оно находится в

"HKLM\software\microsoft\windows nt\currentversion\profilelist", поэтому идентификатор пользователя / профиля?

Допустим, я беру пользователя с именем "computer_user_01" . Это означает, что его "ProfileImagePath" равно "C:\users\computer_user_01".

Итак, допустим, полный путь к этому значению:

`HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-21-3548956479-1181130828-1993911463-1001\ProfileImagePath\C:\users\computer_user_01".

Так что мне нужен S-1-5-21-3548956479-1181130828-1993911463-1001\.

Как получить его из ключа ProfileImagePath, C:\Users\computer_user_01 значение?

Сейчас я могу запросить ключ ProfileImagePath, но он дает мне всех пользователей:

Get-ItemProperty -Path "hklm:\software\microsoft\windows nt\currentversion\profilelist\*\" -Name "ProfileImagePath" 

Как я могу указать это дальше, скажем, это сработало:

Get-ItemProperty -Path "hklm:\software\microsoft\windows nt\currentversion\profilelist\*\" -Name "ProfileImagePath" -Value "C:\users\computer_user_01" 

Надеюсь, вы понимаете.

Ответы [ 3 ]

0 голосов
/ 31 августа 2018

Хорошо, вы использовали Get-ItemProperty -Path "hklm:\software\microsoft\windows nt\currentversion\profilelist\*\", каждый возвращенный объект имеет атрибуты ProfileImagePath и PSChildName, которые содержат все, что вам нужно.

Get-ItemProperty -Path "hklm:\software\microsoft\windows nt\currentversion\profilelist\*\" | ? {$_.ProfileImagePath -eq "C:\users\computer_user_01"} | Select-Object -ExpandProperty PSChildName

Возвращает искомый S-1-5-21-3548956479-1181130828-1993911463-1001

Пояснение:

? {$_.ProfileImagePath -eq "C:\users\computer_user_01"} - Найдите объект с ProfileImagePath вашего пути

Select-Object -ExpandProperty PSChildName - Вывести имя объекта для взрослых

0 голосов
/ 31 августа 2018

Вы можете попробовать следующее:

# First I get the SID    
$sid = (gwmi win32_useraccount | ? {$_.name -eq "computer_user_01"}).SID
# Then the value of the property you look for
(Get-ItemPropertyValue "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$sid\"   -Name "ProfileImagePath")
0 голосов
/ 31 августа 2018

Вы можете сделать:

(Get-ItemProperty -Path "hklm:\software\microsoft\windows nt\currentversion\profilelist\*\" -Name "ProfileImagePath" | 
 Where-Object { $_.ProfileImagePath -eq 'C:\users\computer_user_01' }).PSChildName
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...