简体   繁体   English

Powershell搜索AD用户

[英]Powershell Search for AD Users

I am learning Powershell and use it frequently for adding users to AD Groups. 我正在学习Powershell,并经常使用它来将用户添加到广告组中。 I would like to know if it is possible to search for AD Usernames using the persons common name (ie John Doe = JDoe). 我想知道是否可以使用人员常用名(即John Doe = JDoe)搜索AD用户名。 It is very time consuming and defeats the purpose of using Powershell if I have to use AD Users and Computers to look up their UID every time. 如果我每次必须使用AD用户和计算机来查找其UID,这将非常耗时并且无法使用Powershell。

UPDATE: I tried the Get-ADUser -filter { cn -eq 'John Doe' } and Get-ADUser -filter { Name -eq 'John Doe' } command and I did not receive any output from the console, it immediately went to the next line. 更新:我尝试了Get-ADUser -filter {cn -eq'John Doe'}Get-ADUser -filter {Name -eq'John Doe'}命令,但我没有从控制台收到任何输出,它立即转到下一行。

I also have RSAT installed, just to clarify. 为了澄清,我也安装了RSAT。 I have looked at the technet article on MS' page Get-ADUser to try and figure it out before I posted the OP. 我看过MS网页Get-ADUser上的technet文章,尝试找出它,然后发布OP。

Just to clarify I am looking to search by the Common Name to find that user's Login Name. 只是为了澄清一下,我希望通过“公用名”进行搜索以找到该用户的登录名。 ie Searching 'John Doe' to find 'jdoe' the User Logon Name. 即搜索“ John Doe”以查找“ jdoe”用户登录名。

I'm not sure what your specific question is, but you can use the AD cmdlets to search using ambiguous name resolution (ANR): 我不确定您的具体问题是什么,但是您可以使用AD cmdlet使用歧义名称解析(ANR)进行搜索:

Get-ADUser -LDAPFilter '(anr=jdoe)'

See https://support.microsoft.com/en-us/kb/243299 for more information about ANR. 有关ANR的更多信息,请参见https://support.microsoft.com/zh-cn/kb/243299

To search by the cn attribute only, just change the LDAP filter: 要仅按cn属性进行搜索,只需更改LDAP过滤器:

Get-ADUser -LDAPFilter '(cn=John Doe)'

Yes. 是。 You need to install RSAT. 您需要安装RSAT。 See here for instructions for various Windows versions. 有关各种Windows版本的说明,请参见此处

Then use Get-ADUser : 然后使用Get-ADUser

Get-ADUser -filter { cn -eq "Common Name" }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM