Book Image

Active Directory with PowerShell

By : Pamarthi Venkata Sitaram, YELLAPRAGADA U PADMAVATHI
5 (1)
Book Image

Active Directory with PowerShell

5 (1)
By: Pamarthi Venkata Sitaram, YELLAPRAGADA U PADMAVATHI

Overview of this book

Table of Contents (16 chapters)
Active Directory with PowerShell
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Getting all domain controllers and their site names in the forest


The function discussed in this section is a simple wrapper on top of the Get-ADDomainController cmdlet to query all the domain controllers in forest and display frequently referred-to details, such as DC name, domain name, site name—whether these names are global catalog servers or not—and reachability of the domain controller:

Function Get-DCDetails {
[CmdletBinding()]
Param(
)
$Domains = (Get-ADForest).Domains
$DCs = $Domains | % { Get-ADDomainController -Filter * -Server $_  }
foreach($DC in $DCs) {
  $OutputObj = New-Object -TypeName PSObject -Property @{
          DCName = $User.Name;
          DCDomain = $null;
          IsGC = $null;
          SiteName = $Null;
          IsOnline = $null
        }
  if(Test-Connection -Computer $DC -Count 1 -quiet) {
    $OutputObj.IsOnline = $true
  } else {
    $OutputObj.IsOnline = $false
  }
    $OutputObj.DCName = $DC.HostName
  $OutputObj.DCDomain = $DC.Domain
  $OutputObj.IsGC...