PowerShell Genie

ActiveDirectory module: setup and commands

Module 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Query users, groups and computers with Get-ADUser and Get-ADGroup, then avoid broad searches by choosing a search base and requested properties.

Getting it

Not present by default. Add it with Add-WindowsCapability -Online -Name Rsat.ActiveDirectory.DS-LDS.Tools on Windows 10 or 11, or Install-WindowsFeature RSAT-AD-PowerShell on Windows Server.

Examples

1PS> Search-ADAccount -LockedOut
Show reference output
1 Name SamAccountName Enabled
2 ---------- -------------- -------
3 Jane Smith jsmith True
1PS> Get-ADUser -Filter * -Properties LastLogonDate
Show reference output
1 Name SamAccountName Enabled
2 ---------- -------------- -------
3 Jane Smith jsmith True
4 Alex Jones ajones True

What it is for

Use it for anything living in an on-premises domain, from account lifecycle work through replication health checks. It is also the fastest route to bulk reporting, because -Filter and -LDAPFilter push the selection work onto a domain controller.

Typical tasks

  • Report accounts inactive past a cutoff date
  • Audit membership of privileged groups
  • Find computers with stale last logon values
  • Check replication partner failure counts
  • Bulk update attributes from a CSV
  • Locate the current FSMO role holders

Check the installed version

1PS> Get-Module -ListAvailable ActiveDirectory | Select-Object Name, Version, Path
2PS> Get-Command -Module ActiveDirectory

Compare the module path and version with the session used by your scheduled task or automation account. Use it for anything living in an on-premises domain, from account lifecycle work through replication health checks. It is also the fastest route to bulk reporting, because -Filter and -LDAPFilter push the selection work onto a domain controller.

Primary documentation

Active Directory PowerShell documentation

Continue
Genie guideActiveDirectory module: setup and commands

Query users, groups and computers with Get-ADUser and Get-ADGroup, then avoid broad searches by choosing a search base and requested properties.