PowerShell Genie

PowerShell Active Directory module

The ActiveDirectory module gives you cmdlets for users, groups, computers, OUs and domain configuration. It does not ship with the operating system by default.

Lesson 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Overview

On a server, install it with Install-WindowsFeature RSAT-AD-PowerShell. On Windows 10 or 11, it is an optional feature: Add-WindowsCapability -Online -Name Rsat.ActiveDirectory.DS-LDS.Tools. That difference is the first thing to check when Get-ADUser is not recognised.

The module also brings an AD: PSDrive, so you can browse the directory with Get-ChildItem the way you browse a filesystem. That is occasionally useful and rarely necessary.

Two details will shape every AD script you write. The first is that most Get-AD cmdlets return a small default set of properties, and anything else needs -Properties. The second is that -Filter uses its own syntax, not PowerShell's, and pushing the filter to the domain controller instead of using Where-Object is the difference between a fast query and one that pulls the whole directory.

-Server targets a specific domain controller. Without it you get whichever one you are talking to, which matters when you are chasing replication.

What happens

This checks whether the module is installed rather than assuming it is. An empty result means the RSAT tools are missing, which is the actual cause when Get-ADUser reports that the term is not recognised. Once the module is present, auto-loading means you never need Import-Module ActiveDirectory by hand.

Worth remembering

  • Install with Install-WindowsFeature on a server, Add-WindowsCapability on a client.
  • Get-AD cmdlets return a default subset; use -Properties for more.
  • -Filter uses AD syntax and runs on the DC. Where-Object does not.
  • -Server pins the query to one domain controller.

Primary documentation

Select-Object reference

Try it

Browser simulation · fictional data; no changes to your computer.

Interactive simulation · fictional data

Checks whether the ActiveDirectory module is installed.

Show reference output

Sample output · fictional data, shaped like the real thing

Name             Version  ModuleType
---------------  -------  ----------
ActiveDirectory  1.0.1.0  Manifest  

Practise this

Import the directory module

Import ActiveDirectory, then display its module record.

Review the lesson

Keep going

Next: PowerShell AD users
Genie guidePowerShell Active Directory module

The ActiveDirectory module gives you cmdlets for users, groups, computers, OUs and domain configuration. It does not ship with the operating system by default.