TestimoX

API Reference

Class

DomainHelper

Namespace ADPlayground
Assembly ADPlayground
Modifiers static

Conversion helpers for domain names and distinguished names.

Inheritance

  • Object
  • DomainHelper

Methods

public static String DistinguishedNameToDomainName(String distinguishedName) #
Returns: String

Converts a distinguished name to a domain name.

Parameters

distinguishedName System.String requiredposition: 0
Distinguished name of the domain.

Returns

Domain name string.

public static String DomainNameToDistinguishedName(String domain) #
Returns: String

Converts a domain name to its distinguished name.

Parameters

domain System.String requiredposition: 0
Domain name or distinguished name.

Returns

Distinguished name of the domain.

public static IEnumerable<String> EnumerateDomainControllers(String domainName = null, Func<DomainController, Boolean> filter = null, NetworkCredential credential = null, CancellationToken cancellationToken = null) #
Returns: IEnumerable<String>

Enumerates domain controller host names for a domain or the whole forest.

Parameters

domainName System.String = null optionalposition: 0
Optional domain name.
filter System.Func{System.DirectoryServices.ActiveDirectory.DomainController,System.Boolean} = null optionalposition: 1
Optional filter applied to each domain controller.
credential System.Net.NetworkCredential = null optionalposition: 2
Optional alternate credential for DirectoryServices lookups.
cancellationToken System.Threading.CancellationToken = null optionalposition: 3
Token to cancel the operation.

Returns

Collection of domain controller names.

public static IAsyncEnumerable<String> EnumerateDomainControllersAsync(String domainName = null, Func<DomainController, Boolean> filter = null, NetworkCredential credential = null, CancellationToken cancellationToken = null) #
Returns: IAsyncEnumerable<String>

Asynchronously enumerates domain controller host names for a domain or the whole forest.

Parameters

domainName System.String = null optionalposition: 0
Optional domain name.
filter System.Func{System.DirectoryServices.ActiveDirectory.DomainController,System.Boolean} = null optionalposition: 1
Optional filter applied to each domain controller.
credential System.Net.NetworkCredential = null optionalposition: 2
Optional alternate credential for DirectoryServices lookups.
cancellationToken System.Threading.CancellationToken = null optionalposition: 3
Token to cancel the operation.

Returns

Asynchronous collection of domain controller names.

EnumerateDomainControllersUnfiltered(System.String arg1, System.Net.NetworkCredential arg2, System.Threading.CancellationToken arg3) #

Enumerates domain controller host names without consulting the LDAP engine's temporary ban list. Intended for last‑resort selection paths that still want a concrete host instead of a serverless bind.

Parameters

arg1 System.String required
arg2 System.Net.NetworkCredential required
arg3 System.Threading.CancellationToken required
public static IEnumerable<String> EnumerateDomainControllersViaDnsSrv(String domainName) #
Returns: IEnumerable<String>

Enumerates domain controllers via DNS SRV (_ldap._tcp.dc._msdcs) without LDAP or domain join.

Parameters

domainName System.String requiredposition: 0
public static IEnumerable<String> EnumerateDomainControllersViaDsGetDcName(String domainName) #
Returns: IEnumerable<String>

Attempts to locate a domain controller via DsGetDcName (DNS-based, works when machine is not joined).

Parameters

domainName System.String requiredposition: 0
public static IEnumerable<String> EnumerateDomainControllersViaLdap(String domainName, CancellationToken cancellationToken = null) #
Returns: IEnumerable<String>

Enumerates domain controllers for a domain via LDAP by scanning CN=Sites servers and selecting matching dNSHostName suffixes.

Parameters

domainName System.String requiredposition: 0
cancellationToken System.Threading.CancellationToken = null optionalposition: 1
EnumerateForestDomainNames 2 overloads
public static IEnumerable<String> EnumerateForestDomainNames(String forestName = null, CancellationToken cancellationToken = null) #
Returns: IEnumerable<String>

Enumerates domain names for the specified forest.

Parameters

forestName System.String = null optionalposition: 0
Optional forest name.
cancellationToken System.Threading.CancellationToken = null optionalposition: 1
Token to cancel the operation.

Returns

Collection of domain names.

public static IEnumerable<String> EnumerateForestDomainNames(String forestName, Boolean includeTrustedDomains, CancellationToken cancellationToken = null) #
Returns: IEnumerable<String>

Enumerates domain names for the specified forest, optionally including trusted forests.

Parameters

forestName System.String requiredposition: 0
Optional forest name.
includeTrustedDomains System.Boolean requiredposition: 1
Whether to include trusted forest domains.
cancellationToken System.Threading.CancellationToken = null optionalposition: 2
Token to cancel the operation.

Returns

Collection of domain names.

public static IAsyncEnumerable<String> EnumerateForestDomainNamesAsync(String forestName = null, CancellationToken cancellationToken = null) #
Returns: IAsyncEnumerable<String>

Asynchronously enumerates domain names for the specified forest.

Parameters

forestName System.String = null optionalposition: 0
Optional forest name.
cancellationToken System.Threading.CancellationToken = null optionalposition: 1
Token to cancel the operation.

Returns

Asynchronous collection of domain names.

public static IEnumerable<String> EnumerateForestDomainNamesViaLdap(String forestName = null, CancellationToken cancellationToken = null) #
Returns: IEnumerable<String>

Enumerates forest domain DNS names via LDAP (CN=Partitions) to avoid SDA hangs. Uses crossRef objects with the dnsRoot attribute.

Parameters

forestName System.String = null optionalposition: 0
cancellationToken System.Threading.CancellationToken = null optionalposition: 1
public static Domain GetDomain(String domainName = null) #
Returns: Domain

Retrieves a domain by name or the current domain when no name is provided.

Parameters

domainName System.String = null optionalposition: 0
Optional domain name.

Returns

The Domain object.

public static DomainController GetDomainController(String nameOrDn) #
Returns: DomainController

Attempts to locate a domain controller by name or distinguished name.

Parameters

nameOrDn System.String requiredposition: 0
Name or distinguished name.

Returns

Domain controller instance.

public static DomainMode GetDomainFunctionalLevel(String domainName) #
Returns: DomainMode

Gets the functional level for the specified domain.

Parameters

domainName System.String requiredposition: 0
Name of the domain to query.

Returns

The DomainMode for the domain or Unknown when unavailable.

public static String GetDomainNameFromNetBiosValue(String netBiosName) #
Returns: String

Retrieves the DNS domain name for a NetBIOS domain name by reading CN=Partitions crossRef (dnsRoot). Returns null when it cannot be resolved.

Parameters

netBiosName System.String requiredposition: 0
NetBIOS domain name.

Exceptions

  • ArgumentNullException – Thrown when netBiosName is null.
  • ArgumentException – Thrown when netBiosName is empty or whitespace.
public static String GetDomainSidValue(String domainName) #
Returns: String

Retrieves the SID value for the specified domain.

Parameters

domainName System.String requiredposition: 0
Domain to query.

Returns

Domain SID string or null on failure.

public static Forest GetForest(String forestName = null) #
Returns: Forest

Retrieves a forest by name or the current forest when no name is provided.

Parameters

forestName System.String = null optionalposition: 0
Optional forest name.

Returns

The Forest object.

public static String GetLocalMachineSidValue() #
Returns: String

Retrieves the local machine SID prefix (S-1-5-21-...) when available.

public static String GetNetBiosNameValue(String domainName) #
Returns: String

Retrieves the NetBIOS name for the specified DNS domain name by reading CN=Partitions crossRef (nETBIOSName). Returns null if it cannot be resolved.

Parameters

domainName System.String requiredposition: 0
DNS domain name.
public static Boolean IsReadOnlyDc(String dcName) #
Returns: Boolean

Determines whether the specified domain controller is read only.

Parameters

dcName System.String requiredposition: 0
Domain controller host name.

Returns

true when the DC is read only.

public static Boolean TryGetCurrentDomain(out Domain domain) #
Returns: Boolean

Attempts to get the current domain object.

Parameters

domain System.DirectoryServices.ActiveDirectory.Domain@ requiredposition: 0
When the method returns, contains the domain object.

Returns

true when the machine is domain-joined.

public static Boolean TryGetCurrentDomainName(out String domainName) #
Returns: Boolean

Attempts to get the current domain name.

Parameters

domainName System.String@ requiredposition: 0
When the method returns, contains the domain name.

Returns

true when the machine is domain-joined.

public static Boolean TryGetCurrentForest(out Forest forest, Int32 timeoutSeconds = 3) #
Returns: Boolean

Attempts to get the current forest within a bounded time budget.

Parameters

forest System.DirectoryServices.ActiveDirectory.Forest@ requiredposition: 0
timeoutSeconds System.Int32 = 3 optionalposition: 1
public static Boolean TryGetLocalSiteName(out String site) #
Returns: Boolean

Tries to resolve the local AD site name of this computer.

Parameters

site System.String@ requiredposition: 0
public static String TryGetPdcHostName(String domainName) #
Returns: String

Attempts to resolve the PDC Emulator host name for a domain. Returns null on failure.

Parameters

domainName System.String requiredposition: 0

Properties

public static Forest CurrentForest { get; } #

Gets the current forest with a short safety timeout to avoid hangs on unhealthy DCs. The first successful call caches the Forest instance for reuse. Throws on timeout; callers should prefer Int32) when possible.

public static Domain RootDomain { get; } #

Gets the root domain of the current forest using lazy initialization.

public static String RootDomainName { get; } #

Gets the name of the root domain using lazy initialization.