您的位置:首页 > 运维架构 > Shell

Searching the Active Directory with PowerShell

2009-04-10 09:59 681 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Active Directory 休闲