Unable to export user and emplyeeid from ldap group

只愿长相守 提交于 2021-01-29 05:04:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!