0% found this document useful (0 votes)
36 views3 pages

Get - Active - Directory - Information - With - PowerShell - Script - 1737381381 L

The document provides a guide on using the Get-ADInfo.ps1 PowerShell script to retrieve comprehensive Active Directory information, including counts of computers, users, groups, and details about the AD forest and schema version. It outlines the steps to download, set up, and run the script, emphasizing the efficiency of obtaining all necessary AD data in one output. This approach simplifies the process of gathering AD information compared to manual searches in PowerShell or the GUI.

Uploaded by

Jaydeep
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views3 pages

Get - Active - Directory - Information - With - PowerShell - Script - 1737381381 L

The document provides a guide on using the Get-ADInfo.ps1 PowerShell script to retrieve comprehensive Active Directory information, including counts of computers, users, groups, and details about the AD forest and schema version. It outlines the steps to download, set up, and run the script, emphasizing the efficiency of obtaining all necessary AD data in one output. This approach simplifies the process of gathering AD information compared to manual searches in PowerShell or the GUI.

Uploaded by

Jaydeep
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Get Active Directory information with PowerShell script

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.

Get AD info PowerShell script

The Get-ADInfo.ps1 PowerShell script will get the following AD information:


1. Computers (Workstations + Servers)
2. Workstations
3. Servers
4. Users
5. Groups
6. Active Directory forest name
7. Active Directory forest mode
8. Active Directory domain mode
9. Active Directory schema version
10. FSMO role owners

Download get AD info 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.

#>

# Get counts of different types of objects in Active Directory


$Computers = (Get-ADComputer -Filter * | Measure-Object).Count
$Workstations = (Get-ADComputer -Filter { OperatingSystem -notlike "*Server*" } | Measure-Object).Count
$Servers = (Get-ADComputer -Filter { OperatingSystem -like "*Server*" } | Measure-Object).Count
$Users = (Get-ADUser -Filter * | Measure-Object).Count
$Groups = (Get-ADGroup -Filter * | Measure-Object).Count

# Get Active Directory Forest information


$ADForest = (Get-ADDomain).Forest
$ADForestMode = (Get-ADForest).ForestMode
$ADDomainMode = (Get-ADDomain).DomainMode

# 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' }
}

# Display collected information


Write-host "Active Directory Info" -ForegroundColor Yellow
Write-host ""
Write-Host "Computers = $Computers" -ForegroundColor Cyan
Write-Host "Workstions = $Workstations" -ForegroundColor Cyan
Write-Host "Servers = $Servers" -ForegroundColor Cyan
Write-Host "Users = $Users" -ForegroundColor Cyan
Write-Host "Groups = $Groups" -ForegroundColor Cyan
Write-host ""
Write-Host "Active Directory Forest Name = "$ADForest -ForegroundColor Cyan
Write-Host "Active Directory Forest Mode = "$ADForestMode -ForegroundColor Cyan
Write-Host "Active Directory Domain Mode = "$ADDomainMode -ForegroundColor Cyan
Write-Host "Active Directory Schema Version is $ADNum which corresponds to $srv" -ForegroundColor Cyan
Write-Host ""
Write-Host "FSMO Role Owners" -ForegroundColor Cyan

# Retrieve FSMO roles individually


$Forest = Get-ADForest
$SchemaMaster = $Forest.SchemaMaster
$DomainNamingMaster = $Forest.DomainNamingMaster
$Domain = Get-ADDomain
$RIDMaster = $Domain.RIDMaster
$PDCEmulator = $Domain.PDCEmulator
$InfrastructureMaster = $Domain.InfrastructureMaster

# Display FSMO role owners


Write-Host "Schema Master = $SchemaMaster" -ForegroundColor Cyan
Write-Host "Domain Naming Master = $DomainNamingMaster" -ForegroundColor Cyan
Write-Host "RID Master = $RIDMaster" -ForegroundColor Cyan
Write-Host "PDC Emulator = $PDCEmulator" -ForegroundColor Cyan
Write-Host "Infrastructure Master = $InfrastructureMaster" -ForegroundColor Cyan
Run get AD info PowerShell script

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

Active Directory Forest Name = exoip.local


Active Directory Forest Mode = Windows2016Forest
Active Directory Domain Mode = Windows2016Domain
Active Directory Schema Version is 88 which corresponds to Windows Server 2019/Windows Server 2022

FSMO Role Owners


Schema Master = DC01-2019.exoip.local
Domain Naming Master = DC01-2019.exoip.local
RID Master = DC01-2019.exoip.local
PDC Emulator = DC01-2019.exoip.local
Infrastructure Master = DC01-2019.exoip.local
Here is a screenshot of what it looks like.

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.

You might also like