PowerShell: Forest Information & Find All Global Catalog Servers Script

95 views
Skip to first unread message

Amit Tank

unread,
Apr 5, 2008, 2:44:37 PM4/5/08
to It_disc...@googlegroups.com

http://exchangeshare.wordpress.com/2008/04/05/powershell-find-all-global-catalogs/

 

.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.

image

Here are different Method & Properties of Forest. We can get different information about forest with these Methods and Properties.

image

Some Important Methods & Properties description.

 

Top of Form

Name

Bottom of Form

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.

Bottom of Form

Top of Form

Bottom of Form

Here is an example of FindAllGlobalCatalogs() - This Method will find all GCs of forest.

image 

 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 ...

 

 

Regards,

Amit Tank, MCTS: Exchange 2007, MCSA 2003 - Messaging

 

(M) +91-9900173227

 

mail.png

 

Blog : http://ExchangeShare.WordPress.Com/

 

Group : http://groups.google.co.in/group/It_discussions

 

 

image001.png
image002.png
image003.png
image004.gif
Reply all
Reply to author
Forward
0 new messages