List domain controllers forest wide with OS version
List domain controllers forest wide with OS version

This powershell script will allow you to get a list of your domain controllers and their operating system versions. This script uses information stored in the Active Directory database using the cmdlet get-adcomputer

$list = (Get-ADForest).GlobalCatalogs
$domainnames = (Get-ADForest).Domains

$domainnames_arr = $domainnames| % {
    $domname = $_
    "$domname;" + (($_.split(".") | % {"DC=" + $_ }) -join "," )
}

$DCarray=$domainnames_arr | % {
    $myADobjects = New-Object System.Object
    $dn = $_.split(";")[1]
    $dns = $_.split(";")[0]
    Get-ADComputer -SearchBase "OU=Domain Controllers,$dn" -server "$dns" -Properties OperatingSystem -filter * | `
    select DNSHostName,name,@{l="Domain";e={$dns}},OperatingSystem, @{l="OS Name";e={((($_.OperatingSystem).split(" ")[0..2]) -join " ")}}
}

$DCarray 
<>

My Powershell script categories

List domain controllers forest wide with OS version

Leave a Reply

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