Suppose I have the user id of a user in Active Directory. I'd like to get a list of all AD groups in which that user is currently a member of. How can I do this from the Windows command line?
I've tried the following:
dsget user "DC=jxd123" -memberof
Error:
dsquery failed:'-memberof' is an unknown parameter.
type dsquery /? for help.
Or with the net user command...
Single line, no modules necessary, uses current logged user $($env:username), runs from other windows machines:
Qudos to this vbs/powershell article: http://technet.microsoft.com/en-us/library/ff730963.aspx
You can do this in PowerShell pretty easily. I'm sure you can do it with the ds tools too, but they're old and crusty and PowerShell should be used for everything possible nowadays.
Shorter version
If you need to see your own groups, there's
whoami /groups
:The advantage of this command over
net user /domain username
is that implicit group memberships are also displayed withwhoami
.Found a good resource:
http://social.technet.microsoft.com/wiki/contents/articles/2195.active-directory-dsquery-commands.aspx
Here's how to do it from Windows command prompt:
PowerShell:
Another approach: a PowerShell script that lists all implicit group memberships from the Windows account token. Works on a restricted system.
adfind is another great tool for this sort of thing. It is a free tool from MVP Joe Richards
http://www.joeware.net/freetools/tools/adfind/
You can use one of the shortucts