powershell - 通过 DirectoryEntry 或 DirectorySearcher 指定 Active Directory 域 Controller ?

标签 powershell active-directory domaincontroller directorysearcher

当我想使用这个搜索 AD 时,我可以指定域 Controller :

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

如何使用 DirectoryEntryDirectorySearcher 指定域 Controller ?

最佳答案

Multiple constructor overloads对于 DirectorySearcher,将 DirectoryEntry 作为参数,您可以在创建服务器时针对特定服务器:

# [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

关于powershell - 通过 DirectoryEntry 或 DirectorySearcher 指定 Active Directory 域 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41111738/

相关文章:

powershell - 并行化 Active Directory 查询

azure - 使用新的 Azure 帐户复制默认 Active Directory 条目

powershell - 在 'user' 上找不到对象 'Domain Controller'

powershell - 是否可以在模块中构建一个陷阱方法,然后在其父/全局范围内捕获错误?

sql-server - 如何在Powershell中避免使用SMO对象的系统数据库?

java - 从 MS Azure Active Directory 获取用户组

c# 如何枚举不同域中的 DC

.net - 如何获取.net中ForeignSecurityPrincipals对象的详细信息

string - 在 PowerShell 中拆分字符串

O365 GUI 的 Powershell : permissions