.NET Framework 2.0 has an a NameSpace called System.DirectoryServices.ActiveDirectory.Forest and PowerShell uses it to get AD information.
Forest NameSpace has a method called GetCurrentForest() which will get forest information of your AD environment, here we will save it to $ForestInfo variable.
Here are different Method & Properties of Forest. We can get different information about forest with these Methods and Properties.
Some Important Methods & Properties description.
|
|
Description |
| CreateLocalSideOfTrustRelationship | Creates the local side of a trust relationship with the specified forest. |
| CreateTrustRelationship | Creates both sides of a trust relationship with the specified forest. |
| DeleteLocalSideOfTrustRelationship | Deletes the local side of a trust relationship. |
| DeleteTrustRelationship | Deletes both sides of a trust relationship. |
| FindAllDiscoverableGlobalCatalogs | Finds all of the discoverable global catalogs in this forest. |
| FindAllGlobalCatalogs | Finds all the global catalogs in this forest. |
| FindGlobalCatalog | Finds a single global catalog in this forest. |
| GetAllTrustRelationships | Gets a collection of the trust relationships of the current forest. |
| 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. |
| GetSidFilteringStatus | Gets the SID filtering status of a trust. |
| GetTrustRelationship | Gets the trust relationship between this forest and the specified forest. |
| GetType | Gets the Type of the current instance. (Inherited from Object.) |
| MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
| RaiseForestFunctionality | Raises the mode of operation for the forest. |
| RepairTrustRelationship | Repairs a trust relationship. |
| SetSelectiveAuthenticationStatus | Enables or disables selective authentication for an inbound trust. |
| SetSidFilteringStatus | Sets the SID filtering state with the specified forest. |
| UpdateLocalSideOfTrustRelationship | Overloaded. Updates the password for the local side of a trust relationship. |
| UpdateTrustRelationship | Updates the trust direction for a trust relationship. The trust directions are updated on both sides of the trust. |
| VerifyOutboundTrustRelationship | Verifies that a previously established outbound trust with the specified forest is valid. |
| VerifyTrustRelationship | Verifies that a previously established trust with the specified forest is valid. |
Here is an example of FindAllGlobalCatalogs() – This Method will find all GCs of forest.
Now, Here is a script to find all the Global Catalogs servers in the forest.
========== Script Code ==========
$ForestInfo = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
$GCs = $ForestInfo.FindAllGlobalCatalogs()
ForEach ($GC in $GCs)
{
Write-Host $GC.Name
}
========== Script Code ==========
Same way you can get different information of forest by choosing different Properties & Methods.
I hope this will be useful for you …


