Retrieve Active Directory domain controller OS forest wide

Retrieve Active Directory domain controller OS forest wide

Retrieve Active Directory domain controller OS forest wide

This script uses the information stored in the Active Directory database to retrieve the domain controller FQDNs qnd their operating system. The script follow the steps below

  • enumerate the domain names in the current forest
  • list the domain controllers in each domain
  • retrieve FQDN and OS information for each DC

#init
$array = @()

#list domains in the forest
$domains = (Get-ADForest).Domains

$domains | % {
$dnsDomainName = $_
$DomainControllersOU = (Get-ADDomain $dnsDomainName).DomainControllersContainer
$array += Get-ADcomputer -SearchBase $DomainControllersOU -server $dnsDomainName -filter * -Properties DNSHostName,OperatingSystem | select DNSHostName,OperatingSystem

}

$array

<>

My Powershell script categories

Leave a Reply

Your email address will not be published. Required fields are marked *