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
{
$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
相关文章推荐
- Find Exchange Servers in the Local Active Directory Site using PowerShell
- AD-Powershell for Active Directory Administrators
- sfw5 -active enterprise extensions in the swith frame
- Three Steps to Migrate Group Policy Between Active Directory Domains or Forests Using PowerShell
- Powershell with file and directory
- Managing an Active Directory Environment With Thousands of Subnets
- A file with the correct name was found in this directory, but it is not the correct one.
- Resolvent for Error When Searching Active Directory Using OleDB
- AD-Powershell for Active Directory Administrators
- Authenticate a user against the Active Directory using the user ID and password
- Migrate schema of the Active Directory
- Active Directory Authentication in ASP.NET MVC 5 with Forms Authentication and Group-Based Authorization
- How to Join the vCSA 6.5 to an Active Directory Domain
- Get the SID of an Active Directory User
- AD-Powershell for Active Directory Administrators
- Efficiently traversing InnoDB B+Trees with the page directory--slot
- MySQL编译安装的CMake Error: The source directory "/root/mysql-5.6.10/-with-ssl" does not exist.
- Extending the Active Directory Schema
- How to use the windows active directory to authenticate user via logon form 如何自定义权限系统,使用 active directory验证用户登录
- [Angular2 Router] Style the Active Angular 2 Navigation Element with routerLinkActive