Getting Domain for User with DSQuery | DSGet

1k Views Asked by At

Using DSQuery and DSGet to get user attributes that are needed to make accounts (not associated with their Windows account). The current command I've got is:

dsquery * -filter "(&(objectCategory=Person)(objectclass=User)([email protected]))" | dsget user -samid -fn -ln -office -email > user.txt

which gets me all the information I need except the domain the user is associated with. There's the attribute in AD called User logon name (pre-Windows 2000) (first box), but as far as I can tell DSGet doesn't return that. I know the DSQuery can get me the groups the user is in but I'm not sure if there's an easy (one-liner) that can get the info needed. Any guidance or help is appreciated.

1

There are 1 best solutions below

0
RahulKumarShaw On

There is no attribute User logon name (pre-Windows 2000) in Attribute Editor so there is another way we can get the user logon name using distinguish name (DN) and UPN(User logon Name) enter image description here

please use the below command to get the DN

This is for user

dsquery * -filter "(&(objectCategory=Person)(objectclass=user)([email protected]))" | dsget user "CN=RahulShaw,CN=Users,DC=microsoft,DC=com" -samid -fn -ln -office -email -DN -UPN > Ansuman.txt

enter image description here

This is under Domain Users

dsquery * -filter "(&(objectCategory=Group)(objectclass=group)([email protected]))" | dsget group "CN=Domain Users,CN=Users,DC=microsoft,DC=com" -samid -DN > ipsita.txt

enter image description here