问题
I am trying to export user and employeeid from LDAP. All the users are in a group that I extracted using the code bellow. I also put them in a csv file.
How can I retrieve employeeid for each user ? Changing this query or creating a new one and using the csv file.
$groups = @()
$groups = 'CONBR-MES-DEV-USERS'
Write-Host 'Group_Name','Member'
foreach ($group in $groups)
{
$members = @()
$members = Get-ADGroupMember -Server la.jnj.com -Identity $group
foreach ($member in $members)
{
Write-Host $member.SamAccountName
}
}
I want something like userA 123456 userB 987654 and so on
回答1:
The employeeID
attribute is not included in the default attribute set. One way you can fix this is to use Get-ADObject
inside the loop and include the attribute. Example:
foreach ( $group in $groups ) {
$members = Get-ADGroupMember -Server la.jnj.com -Identity $group
foreach ( $member in $members ) {
$groupMember = $member | Get-ADObject -Properties employeeID,sAMAccountName
[PSCustomObject] @{
"Name" = $groupMember.sAMAccountName
"employeeID" = $groupMember.employeeID
}
}
}
回答2:
This can be performed without looping using a LDAP_MATCHING_RULE_IN_CHAIN filter similar to: (memberOf:1.2.840.113556.1.4.1941:=CN=yourgorupname,OU=Groups,DC=example,DC=net)
and returning attributes: "sAMAccountName" "employeeID"
-jim
来源:https://stackoverflow.com/questions/56839400/unable-to-export-user-and-emplyeeid-from-ldap-group