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'
 
摘自: [url]http://blogs.technet.com/benp/archive/2007/03/26/searching-the-active-directory-with-powershell.aspx[/url]

你可能感兴趣的:(Directory,powershell,休闲,Active,searching)