LDAPグループメンバーシップ(ドメインユーザーを含む)
-
10-10-2019 - |
質問
たとえそのグループがたまたま一部のユーザーの主要なグループであっても、LDAPグループ内のユーザーのリストを取得するにはどうすればよいですか?
たとえば、「ドメインユーザー」がドイツ語の「ドメインルート」であると仮定します。 「cn = domain leute、dc = mycompany、dc = com」のすべてのメンバーが欲しいです。それがよく知られている「ドメインユーザー」グループであることをどうやって知るでしょうか?
または、一部のユーザーのプライマリグループが「CN = Rebels、DC = mycompany、dc = com」に変更された場合はどうなりますか?ユーザーはプライマリグループのメンバープロパティを持っておらず、プライマリグループにはそれらをリストするメンバープロパティがありません。
これは、LDAPで表示されたときに見られるものです(つまり、MS拡張機能はありません):
解決
最初にグループオブジェクトからPrimaryGruptokenを見つける必要があります。 AdSiedITを使用している場合は、この計算された属性を確認するために「構築」フィルターがあることを確認する必要があります。ドメインユーザーの場合、PrimaryGruptokenは513でなければなりません。
次に、PrimaryGroupIDのすべてのユーザーをこの値に設定していることを確認します。以下は、プライマリグループとして設定されたドメインユーザーを持つすべてのユーザーを確認するために書く必要があるLDAPクエリです。
(&(objectCategory=person)(objectClass=user)(primaryGroupID=513))
編集
LDAPブラウザでPrimaryGruptokenを表示する手順は次のとおりです。 LDAPブラウザ2.6ビルド650を使用しています。プロフィールを右クリックしてプロパティをクリックします
LDAP設定]タブに移動し、[Advanced]ボタンをクリックします。
追加の動作属性を追加します PrimaryGruptoken
クリック 申し込み プロパティ]ページをボタンと閉じます。今、あなたは見るべきです PrimaryGruptoken あなたのグループオブジェクトで。
他のヒント
特定のグループからプライマリグラプトを作成するには、ObjectSIDから抽出するため、たとえば ドメインユーザー objectsid = S-1-5-21-704657944-2065781323-617630493-513
そうして PrimaryGruptoken 「 - 」の後の最後の数字です。「ドメインユーザー」の場合は 513
これは私がまさにそれをするように作ったPSスクリプトです:
[void][System.Reflection.Assembly]::LoadWithPartialName("System.DirectoryServices");
$groupName = "Grupo Domain";
$directoryEntry = New-Object System.DirectoryServices.DirectoryEntry;
$directorySearcher = New-Object System.DirectoryServices.DirectorySearcher($directoryEntry, "(&(objectClass=group)(CN=$groupName))");
[void]$directorySearcher.PropertiesToLoad.Add("objectSid");
[void]$directorySearcher.PropertiesToLoad.Add("member");
$result = $directorySearcher.FindOne();
if ($result -eq $null) { return; }
# Try get the group members through the "member" property.
if ($result.Properties["member"].Count -gt 0) {
foreach ($member in $result.Properties["member"]) {
$memberSearcher = New-Object System.DirectoryServices.DirectorySearcher($directoryEntry, "(&(objectClass=*)(distinguishedName=$member))");
[void]$memberSearcher.PropertiesToLoad.Add("msDS-PrincipalName");
$memberResult = $memberSearcher.FindOne();
if ($memberResult -eq $null) { continue; }
Write-Output $memberResult.Properties["msDS-PrincipalName"];
}
return;
}
if ($result.Properties["objectSid"].Count -gt 0) {
# The group might be an AD primary group. Try get the members by the PrimaryGroupID.
$groupSid = New-Object System.Security.Principal.SecurityIdentifier($result.Properties["objectSid"][0], 0);
# Hacky way to get only the last RID.
$primaryGroupSid = $groupSid.Value.Replace($groupSid.AccountDomainSid.ToString(), [String]::Empty).TrimStart('-');
$memberSearcher = New-Object System.DirectoryServices.DirectorySearcher($directoryEntry, "(&(objectClass=*)(primaryGroupId=$primaryGroupSid))");
[void]$memberSearcher.PropertiesToLoad.Add("msDS-PrincipalName");
$memberResult = $memberSearcher.FindAll();
if ($memberResult -eq $null) { continue; }
foreach ($member in $memberResult) {
Write-Output $member.Properties["msDS-PrincipalName"];
}
}