With this script, you will be able to retrieve the domain controller hostnames in a forest.

$myForest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
$myforest.Sites | % { $_.Servers } | Select Name, Domain

References

MSDN Forest Class

Properties
Name Description
Public property ApplicationPartitions Gets a collection of all application partitions in the forest.
Public property Domains Gets a collection of all domains in the forest.
Public property ForestMode Gets the operating mode of the forest.
Public property GlobalCatalogs Gets a collection of all global catalogs in the forest.
Public property Name Gets the name of the forest.
Public property NamingRoleOwner Gets the domain controller that holds the FSMO naming master role for the forest.
Public property RootDomain Gets the first domain that was created in a forest.
Public property Schema Gets the schema of the forest.
Public property SchemaRoleOwner Gets the domain controller that holds the FSMO schema master role for the forest.
Public property Sites Gets a collection of sites that are contained in the forest.
Methods
Name Description
Public method CreateLocalSideOfTrustRelationship Creates the local side of a trust relationship with the specified forest.
Public method CreateTrustRelationship Creates both sides of a trust relationship with the specified forest.
Public method DeleteLocalSideOfTrustRelationship Deletes the local side of a trust relationship.
Public method DeleteTrustRelationship Deletes both sides of a trust relationship.
Public method Dispose() Releases all managed and unmanaged resources that are held by the object.
Protected method Dispose(Boolean) Releases the managed resources that are used by the object and, optionally, releases unmanaged resources.
Public method Equals(Object) Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method FindAllDiscoverableGlobalCatalogs() Finds all of the discoverable global catalogs in this forest.
Public method FindAllDiscoverableGlobalCatalogs(String) Finds all of the discoverable global catalogs in this forest in a specified site.
Public method FindAllGlobalCatalogs() Finds all the global catalogs in this forest.
Public method FindAllGlobalCatalogs(String) Finds all the global catalogs in this forest for a given site.
Public method FindGlobalCatalog() Finds any global catalog in this forest.
Public method FindGlobalCatalog(LocatorOptions) Finds a global catalog in this forest for a specified location criteria.
Public method FindGlobalCatalog(String) Finds a global catalog in this forest for a specified site.
Public method FindGlobalCatalog(String, LocatorOptions) Finds a global catalog in this forest for a specified site and location criteria.
Public method GetAllTrustRelationships Gets a collection of the trust relationships of the current forest.
Public methodStatic member GetCurrentForest Gets a Forest object for the current user context.
Public methodStatic member GetForest Gets a Forest object for the specified context.
Public method GetHashCode Serves as the default hash function. (Inherited from Object.)
Public method GetSelectiveAuthenticationStatus Gets a Boolean value that indicates whether selective authentication is enabled on the inbound trust relationship with the specified forest. true if selective authentication is enabled; otherwise,false. For more information, see the Remarks section.
Public method GetSidFilteringStatus Gets the SID filtering status of a trust.
Public method GetTrustRelationship Gets the trust relationship between this forest and the specified forest.
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method RaiseForestFunctionality Raises the mode of operation for the forest.
Public method RepairTrustRelationship Repairs a trust relationship.
Public method SetSelectiveAuthenticationStatus Enables or disables selective authentication for an inbound trust.
Public method SetSidFilteringStatus Sets the SID filtering state with the specified forest.
Public method ToString Returns a string representation of the current forest. (Overrides Object.ToString().)
Public method UpdateLocalSideOfTrustRelationship(String, String) Updates the password for the local side of a trust relationship.
Public method UpdateLocalSideOfTrustRelationship(String, TrustDirection, String) Updates the password and trust direction for the local side of a trust relationship.
Public method UpdateTrustRelationship Updates the trust direction for a trust relationship. The trust directions are updated on both sides of the trust.
Public method VerifyOutboundTrustRelationship Verifies that a previously established outbound trust with the specified forest is valid.
Public method VerifyTrustRelationship Verifies that a previously established trust with the specified forest is valid.
Retrieve the domain controller hostnames in a forest

Leave a Reply

Your email address will not be published.