I can specify the domain controller when I want to search through AD using this:
$principalContext = New-Object 'System.DirectoryServices.AccountManagement.PrincipalContext'([System.DirectoryServices.AccountManagement.ContextType]::Domain, $DomainControllerIpAddress, $Container)
How can I specify the domain controller using a DirectoryEntry
or DirectorySearcher
?
Multiple constructor overloads for the
DirectorySearcher
take aDirectoryEntry
as it's argument, and you can target a specific server when creating one: