通过DirectoryEntry或DirectorySearcher指定Active Directory域控制器?

时间:2016-12-13 00:09:21

标签: powershell active-directory domaincontroller directorysearcher

当我想使用此搜索AD时,我可以指定域控制器:

'$filter'

如何使用$principalContext = New-Object 'System.DirectoryServices.AccountManagement.PrincipalContext'([System.DirectoryServices.AccountManagement.ContextType]::Domain, $DomainControllerIpAddress, $Container) DirectoryEntry

指定域控制器

1 个答案:

答案 0 :(得分:3)

Multiple constructor overloads DirectorySearcherDirectoryEntry作为参数,您可以在创建一个特定服务器时定位:

# [adsi] is a type accelerator for the DirectoryEntry class
$Entry = [adsi]"LDAP://dc01.domain.tld/OU=MyContainer,DC=domain,DC=tld"

# [adsisearcher] is a type accelerator for the DirectorySearcher class
$Searcher = [adsisearcher]$Entry