从命令行获取用户的非截断Active Directory组

时间:2009-09-22 03:45:27

标签: windows cmd active-directory

我经常使用net user命令查看用户的AD组:

net user /DOMAIN <username>

这很有效,但是组名被截断为大约20个字符。在我的组织中,大多数组名都比这长得多。

有没有人知道通过命令行获取非截断的AD组的方法?

7 个答案:

答案 0 :(得分:97)

GPRESULT是正确的命令,但不能在没有参数的情况下运行。如果没有输出到文本文件,则很难管理/v或详细选项。例如。我建议使用

gpresult /user myAccount /v > C:\dev\me.txt - 确保C:\ Dev \ me.txt存在

另一种选择是仅显示在命令窗口中可以完全显示的摘要信息:

gpresult /user myAccount /r

帐户列在标题下:

The user is a part of the following security groups
---------------------------------------------------

答案 1 :(得分:48)

有点陈旧的帖子,但我想到了什么。是&#34; whoami&#34;满足你的需求?

我今天刚刚发现它(实际上来自同一个谷歌搜索带我到这里)。自XP以来,Windows已经有了一个whoami工具(添加工具包的一部分),并且自Vista以来一直内置。

whoami /groups

列出当前登录用户的所有AD组。我相信它确实要求您以该用户身份登录,因此如果您的用例需要能够运行命令来查看其他用户,那么这将无济于事。

答案 2 :(得分:5)

或者您可以使用 dsquery dsget

dsquery user domainroot -name <userName> | dsget user -memberof

要检索组成员身份,请执行以下操作:

Tue 09/10/2013 13:17:41.65
C:\
>dsquery user domainroot -name jqpublic | dsget user -memberof
"CN=Technical Support Staff,OU=Acme,OU=Applications,DC=YourCompany,DC=com"
"CN=Technical Support Staff,OU=Contosa,OU=Applications,DC=YourCompany,DC=com"
"CN=Regional Administrators,OU=Workstation,DC=YourCompany,DC=com"

虽然我找不到任何证据证明我曾在计算机上安装过此软件包,但您可能需要安装远程服务器管理工​​具(适用于Windows 7)

答案 3 :(得分:0)

答案 4 :(得分:0)

根据P.Brian.Mackey的回答-我尝试使用 gpresult /user <UserName> /r 命令,但它似乎仅对我的用户帐户有效;对于其他用户帐户,我得到以下结果:The user "userNameHere" does not have RSOP data

因此,我通读了https://blog.thesysadmins.co.uk/group-policy-gpresult-examples.html--这个博客,并提出了解决方案。您必须知道用户的计算机名称:

gpresult /s <UserComputer> /r /user:<UserName>

运行命令后,您必须ENTER几次才能完成程序,因为它会在输出中间暂停。此外,结果还提供了一系列数据,其中包括“ COMPUTER SETTINGS> Applied Group Policy Objects”部分,然后是“ COMPUTER SETTINGS> Security groups”,最后是“ USER SETTINGS> security groups ”(这就是我们正在使用列出的带有非截断描述的广告组进行搜索!)。

有趣的是,GPRESULT具有一些在NET USER命令中看不到的额外成员。此外,排序顺序不匹配且不是字母顺序。任何可以在评论中增加更多见解的机构。

结果:gpresult (with ComputerName, UserName)

出于安全原因,我只包括一部分成员资格结果。 (总共36个样本,共12个样本)

The user is a part of the following security groups
---------------------------------------------------
..
 Internet Email 
 GEVStandardPSMViewers  
 GcoFieldServicesEditors    
 AnimalWelfare_Readers  
 Business Objects   
 Zscaler_Standard_Access    
..
 GCM    
..
 GcmSharesEditors   
 GHVStandardPSMViewers  
 IntranetReportsViewers 
 JetDWUsers     -- (NOTE: this one was deleted today, the other "Jet" one was added)
..
 Time and Attendance Users  
..

结果:net user /DOMAIN (with UserName)

出于安全原因,我只包括一部分成员资格结果。 (共23个样本,共12个样本)

Local Group Memberships  
Global Group memberships    ...
                             *Internet Email       *GEVStandardPSMViewers
                             *GcoFieldServicesEdito*AnimalWelfare_Readers
                             *Business Objects     *Zscaler_Standard_Acce
                             ...
                             *Time and Attendance U*GCM
                             ...
                             *GcmSharesEditors     *GHVStandardPSMViewers
                             *IntranetReportsViewer*JetPowerUsers
The command completed successfully.

答案 5 :(得分:0)

在PowerShell中更简单的方法:

/** * Loads the specified context. * * Contexts may be used by accessing the context directly. * * @param string $context name of the context or full class name that * defines the context * * @throws LoaderException if the specified context doesn't exist */ public static function load($context = '') { if (empty($context)) { $context = self::$defaultContext; } if ($context[0] !== '\\') { // Short context name (must be formatted into class name). $context = self::$contextPrefix . $context; } if (!class_exists($context)) { throw @new LoaderException( 'Specified context ("' . $context . '") does not exist.', >>>>>>>> $context <======= exception is thrown here ); } self::$loadedContext = $context; self::$KEYWORDS = $context::$KEYWORDS; }

要求:您自己运行的帐户必须与目标用户属于同一域的成员,除非您指定Get-ADPrincipalGroupMembership <username>-Credential(未经测试)。

答案 6 :(得分:-6)

您可以解析GPRESULT命令的输出。