While easy on Linux, not as easy on Windows from what I've been able to gather so far. I've found the command that kinda does what I want which is:

net user username /domain 

However I wish to strip all of the data except for the list of the groups. I think findstr may be the answer but I'm not sure of how to use this to do that. Essentially, I guess the script would do something like this (unless there is a more specific command which would be fabulous):

net user username /domain > temp.txt findstr (or some other command) file.txt > groups.txt del temp.txt 

The output of the data would be a list like this:

group1; group2; group3

Now, I could be going about this a complicated way, so as I mentioned if there is a command that can output ONLY a user's security groups that would be fantastic.

3

3 Answers

Use PowerShell!

$user = [wmi] "Win32_UserAccount.Name='JohnDoe',Domain='YourDomainName'" $user.GetRelated('Win32_Group') 

or only for group names:

$user = [wmi] "Win32_UserAccount.Name='JohnDoe',Domain='YourDomainName'" $user.GetRelated('Win32_Group') | Select Name 

Hmm.

net user paul /domain | find "Global Group memberships" 

Will give you the the groups, but if you don't want the header you'd need something more involved:

for /f "tokens=4*" %f in ('net user paul /domain ^| find "Global Group memberships"') do echo %f 

So %f contains the groups.

3
dsquery user -name "My Full Name" | dsget user -memberof | dsget group -samid 

I found this pretty much gives me what I was looking for, in case anyone was curious! :)

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy