PowerShell to Find Name & OS Version of Domain Controllers

Previous week i received a request from SM to get the all domain controllers OS details as there are some of windows 2008 R1 domain controllers still existing in our environment and need to migrated to 2012 R2 .There are number of domain controllers in our environment or we can say around 1000 domain controllers in different locations across the world.

Below is the powershell script to get the domain controller name with OS details. it get the details from Domain Controllers OU and if you are aware about every objects in active directory contains the operating system information as below.

$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 ” “)}}


If you have any questions feel free to contact us on admin@windowstechno.com also follow us on facebook @windowstechno to get updates about new blog posts.

How useful was this post?

Click on a star to rate it!

Leave a Reply