随笔 - 24, 文章 - 0, 评论 - 1, 引用 - 0
数据加载中……

Searching the Active Directory with PowerShell

 

function get-dn ($SAMName) 



$root 
= [ADSI]'

$searcher 
= new-object System.DirectoryServices.DirectorySearcher($root) 

$searcher.filter 
= "(&(objectClass=user)(sAMAccountName= $SAMName))" 

$user 
= $searcher.findall() 

if ($user.count -gt 1



$count 
= 0 

foreach($i 
in $user) 



write-host $count "" $i.path 

$count 
= $count + 1 



$selection 
= Read-Host "Please select item: " 

return $user[$selection].path 



else 



return $user[0].path 





$Name 
= $args[0

$path 
= get-dn $Name 

"'" + $path + "'" 


举例:

PS C:\store\ps scripts> .\get-dn.ps1 administrator 

'LDAP://CN=Administrator,CN=Users,DC=umpadom,DC=com' 

 

摘自:http://blogs.technet.com/benp/archive/2007/03/26/searching-the-active-directory-with-powershell.aspx

posted on 2009-04-10 09:59 nicktang 阅读(242) 评论(0)  编辑 收藏 引用 所属分类: Powershell

只有注册用户登录后才能发表评论。