Get - Active - Directory - Information - With - PowerShell - Script - 1737381381 L
Get - Active - Directory - Information - With - PowerShell - Script - 1737381381 L
How to get Active Directory info in one output? For example, you want to migrate Active Directory to a new server,
and you like to get the AD info. Or you like to know how many workstations, servers, or groups are present in AD? In
this article, you will learn how to get Active Directory information with PowerShell script.
Download and place Get-ADInfo.ps1 PowerShell script in the C:\scripts folder. If you don’t have a scripts folder, create
one.
Ensure that the file is unblocked to prevent any errors when running the script.
Another option is to copy and paste the code below into Notepad. Give it the name Get-ADInfo.ps1 and place it in
the C:\scripts folder.
<#
.SYNOPSIS
Get-ADInfo.ps1
.DESCRIPTION
Get Active Directory information.
#>
# Obtain Active Directory Schema version and translate it to the corresponding Windows Server version
$ADVer = Get-ADObject (Get-ADRootDSE).schemaNamingContext -Property objectVersion | Select-Object
objectVersion
$ADNum = $ADVer -replace "@{objectVersion=", "" -replace "}", ""
switch ($ADNum) {
'91' { $srv = 'Windows Server 2025' }
'88' { $srv = 'Windows Server 2019/Windows Server 2022' }
'87' { $srv = 'Windows Server 2016' }
'69' { $srv = 'Windows Server 2012 R2' }
'56' { $srv = 'Windows Server 2012' }
'47' { $srv = 'Windows Server 2008 R2' }
'44' { $srv = 'Windows Server 2008' }
'31' { $srv = 'Windows Server 2003 R2' }
'30' { $srv = 'Windows Server 2003' }
}
Run PowerShell as administrator. Next, run the PowerShell script to gather the Active Directory information.
C:\scripts\.\Get-ADInfo.ps1
This is how the output looks like in our organization.
Active Directory Info
Computers = 5
Workstions = 1
Servers =4
Users = 74
Groups = 88
You learned how to get Active Directory information with PowerShell script. There is a lot of information in Active
Directory, and searching for the info one by one in PowerShell or the GUI takes a lot of time. Running a PS script and
having it all in one output saves time and is easier to look at.