Home ยป PowerShell ยป Find Operating System Version of Domain Controllers

Find Operating System Version of Domain Controllers

Recently, I have a requirement to get list of operating system version of domain controllers and export to csv name and OS version of domain controllers and use it for OS upgrade task.

PowerShell Get-AdDomainController active directory gets domain controller information, it has name and operating system version information.

Get Domain Controller OS version and Name
Get Domain Controller OS version and Name

In this article, I will explain how to get name and operating system version of domain controllers and export it to csv file in PowerShell.

Get List of Domain Controller OS Version

Use Get-AdDomainController active directory cmdlet to get list of domain controller name and OS version with using below command

 Get-ADDomainController -Filter * | Select-Object Name, OperatingSystem

In the above PowerShell command, Get-AdDomainController gets all domain controller using Filter and wild card character and pass domain controller objects to second command.

Second command uses Select-Object to select Name and Operating System version of domain controllers.

Output of above command to find OS version of domain controller as below

PS C:\Windows\system32> Get-ADDomainController -Filter * | Select-Object Name, OperatingSystem

Name     OperatingSystem
----     ---------------
ENGG-PRO Windows Server 2019 Datacenter


PS C:\Windows\system32>

To export domain controller name and operating system version to csv file, use below command

 Get-ADDomainController -Filter * | Select-Object Name, OperatingSystem | Export-Csv -Path C:\DomainController_OSVersion.csv -NoTypeInformation

In the above PowerShell command, it uses Export-Csv cmdlet to export list of domain controller having name and OS version.

Cool Tip: How to get active directory organizational unit in PowerShell!

Get Name and OS Version of Specific Domain Controller

If you want to get name and OS version of specific domain controller, use below command

Get-ADDomainController -Identity "ENGG-PRO.SHELLPRO.LOCAL" | Select-Object Name, OperatingSystem

In the above PowerShell script, Get-AdDomainController get name and OS version of domain controller specified by Identity parameter.

Conclusion

I hope above article on how to find name and operating system version of domain controller helpful to you.

You can use Export-Csv cmdlet to export domain controller name and OS version.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on ShellGeek home page.

Leave a Comment