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 /domainHowever 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.txtThe 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.
33 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 %fSo %f contains the groups.
3dsquery user -name "My Full Name" | dsget user -memberof | dsget group -samidI found this pretty much gives me what I was looking for, in case anyone was curious! :)