Ying Li at myITforum.com

PowerShell & System Center

PowerShell to identify the GlobalCatalog Servers and more in your AD environment - Part II

Lets continue play with AD using PowerShell.

PS C:\Documents and Settings\yl.admin\My Documents\PS>$myforest = [System.DirectoryServices.AcitveDirectory.Forest]::GetCurrentForest()

PS C:\Documents and Settings\yl.admin\My Documents\PS> $myforest.Sites


Name                           : NYT
Domains                        : {mydomain.com}
Subnets                        : {xxx.yyy.0/16}
Servers                        : {dc1.mydomain.com, NYTDCP01.mydomain.com, NYTDCP02.mydomain.com, dc2.mydomain.com}
AdjacentSites                  : {COA, NYH, NJC, NYR...}
SiteLinks                      : {NYT-To-COP-10, NYT-To-NJC-10, NYT-To-NY5-10, NYT-To-NYB-10...}
InterSiteTopologyGenerator     : NYTDCP02.mydomain.com
Options                        : None
Location                       : NY/TW
BridgeheadServers              : {NYTDCP02.mydomain.com, NYTDCP01.mydomain.com, dc1.mydomain.com, dc2.mydomain.com}
PreferredSmtpBridgeheadServers : {}
PreferredRpcBridgeheadServers  : {}
IntraSiteReplicationSchedule   :

Name                           : NJC
Domains                        : {mydomain.com}
Subnets                        : {}
Servers                        : {njc.mydomain.com}
AdjacentSites                  : {NYH, NYT, CAL, CAG...}
SiteLinks                      : {NYT-To-NJC-10, NJC-To-CAL-100, NJC-To-CAG-100, NJC-To-CAI-100...}
InterSiteTopologyGenerator     : njcdcp01.mydomain.com
Options                        : None
Location                       : New Jersey
BridgeheadServers              : {njcdcp01.mydomain.com}
PreferredSmtpBridgeheadServers : {}
PreferredRpcBridgeheadServers  : {}
IntraSiteReplicationSchedule   :

 .

.

Two things I don’t like about the output is:

1) The format

2) What about the information after … – we simply can’t see!

 So I gathered enough strength and time to write a script to get the output into excel format which I like (My bosses like too!) and to enumerate through those arrays to get complete information:

$a = New-Object -comobject Excel.Application
$a.visible = $True

$b = $a.Workbooks.Add()
$c = $b.Worksheets.Item(1)

$c.Cells.Item(1,1) = "SiteName"
$c.Cells.Item(1,2) = "Domains"
$c.Cells.Item(1,3) = "Subnets"
$c.Cells.Item(1,4) = "Servers"
$c.Cells.Item(1,5) = "AdjacentSites"
$c.Cells.Item(1,6) = "SiteLinks"
$c.Cells.Item(1,7) = "ISTG"
$c.Cells.Item(1,8) = "Location"
$c.Cells.Item(1,9) = "BridgeheadServers"
$c.Cells.Item(1,10) = "Report Time Stamp"


$d = $c.UsedRange
$d.Interior.ColorIndex = 19
$d.Font.ColorIndex = 11
$d.Font.Bold = $True

$intRow = 2

$MyForest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
$Sites = MyForest.Sites
Foreach($Site in $Sites)
{
$c.Cells.Item($intRow,1)  = $Site.Name
 Foreach ($domain in $Site.domains)
 {$Dom+=$domain.name + ";"
  $c.Cells.Item($intRow,2)  = $Dom}

 Foreach($Subnet in $Site.Subnets)
 {$Sub+=$Subnet.name + ";"
         $c.Cells.Item($intRow,3)  = $Sub}

 Foreach($Server in $Site.Servers)
 {$Ser+=$Server.name + ";"
  $c.Cells.Item($intRow,4)  = $Ser}

 Foreach($adjacentSite in $site.adjacentSites)
 {$adj+= $adjacentSite.name + ";" 
  $c.Cells.Item($intRow,5)  = $Adj}

 Foreach($SiteLink in $Site.SiteLinks)
 {$Sit += $SiteLink.name + ";"
  $c.Cells.Item($intRow,6)  = $Sit}

$c.Cells.Item($intRow,7)  = $Site.InterSiteTopologyGenerator.name
$c.Cells.Item($intRow,8)  = $Site.Location

 Foreach($BridgeHead in $Site.BridgeheadServers)
 {$Bri += $BridgeHead.name + ";"
  $c.Cells.Item($intRow,9)  = $Bri}

$c.Cells.Item($intRow,10) = Get-date

$Dom = $null
$Sub = $null
$Ser = $null
$adj = $null
$Sit = $null
$Bri = $null
 
$intRow = $intRow + 1


}
$d.EntireColumn.AutoFit()

 


 

 

 

Posted: Apr 21 2008, 07:47 PM by yli628 | with no comments
Filed under: ,

Comments

No Comments