PowerShell Commands for Active Directory Administration
Active Directory administration with PowerShell relies on the ActiveDirectory module, part of the Remote Server Administration Tools. Once imported, cmdlets let you query, create, modify, and remove directory objects across the domain. The examples below assume you have the module installed and are running with appropriate domain credentials. Where commands vary between Windows Server versions, that distinction is noted.
More from this site
Keep reading the latest coverage
Managing Users
User objects are the most common target in AD automation. The following commands create a new user, set properties, enable the account, and reset a password. They also show how to retrieve and filter user data efficiently.
- New-ADUser — creates a user account with parameters like Name, SamAccountName, UserPrincipalName, Path, and AccountPassword.
- Set-ADUser — modifies attributes such as title, department, office, or telephone number.
- Get-ADUser — retrieves users with filters, property expansion, and output formatting.
- Enable-ADAccount / Disable-ADAccount — toggles the user account lockout state.
- Set-ADAccountPassword — resets a password and controls whether the user must change it at next logon.
A typical workflow creates a user, sets a temporary password, enables the account, and adds the user to a group in a single pipeline.
Managing Groups
Groups centralize permissions and simplify delegation. PowerShell supports security groups and distribution groups, with commands for creation, membership management, and listing.
- New-ADGroup — creates a group, specifying GroupScope (Global, DomainLocal, Universal) and GroupCategory (Security or Distribution).
- Add-ADGroupMember — adds one or more members by identity, supporting pipelines for bulk operations.
- Remove-ADGroupMember — removes members, with the -Confirm parameter to prevent accidental deletions.
- Get-ADGroupMember — lists members of a group recursively when the -Recursive switch is used.
- Get-ADGroup — queries groups by filter, such as name pattern or group scope.
Organizational Units and Computers
OUs structure the directory and determine where objects are housed and which Group Policy objects apply. Computers represent the workstation and server inventory.
- New-ADOrganizationalUnit — creates an OU, optionally protecting it from accidental deletion.
- Move-ADObject — relocates objects between OUs.
- Get-ADComputer — lists computers, with filtering by operating system, last logon timestamp, or name pattern.
- New-ADComputer — pre-stages a computer account in a specific OU.
- Set-ADComputer — updates descriptions, operating system attributes, or managedBy references.
Domain and Forest-Level Operations
Higher-level objects like domains and sites are less frequently manipulated but are essential for multi-domain and multi-site environments.
- Get-ADDomain — retrieves domain-level information such as domain mode, DNS root, and PDCE emulator.
- Get-ADForest — provides forest-level details, including the domains and sites container.
- Get-ADReplicationPartnerMetadata — surfaces replication health and last successful replication between domain controllers.
Best Practices for AD PowerShell Scripts
Effective automation with PowerShell commands for Active Directory follows a few consistent patterns. Use -WhatIf and -Confirm to preview destructive actions. Filter on the server side with LDAP filters in Get-AD* cmdlets rather than pulling all objects and filtering locally. Store credentials securely with Get-Credential and pass them via the -Credential parameter. Version your scripts and test them in a lab before running them against production.
| Task | Primary Cmdlet | Key Parameter |
|---|---|---|
| Create user | New-ADUser | -Path, -AccountPassword, -Enabled |
| Find inactive users | Search-ADAccount | -AccountInactive, -TimeSpan |
| Bulk add to group | Add-ADGroupMember | -Members (pipeline-ready) |
| Move object to OU | Move-ADObject | -TargetPath |
| Reset password | Set-ADAccountPassword | -Reset, -NewPassword |
PowerShell transforms routine Active Directory administration into repeatable, auditable workflows. The cmdlets cover the full lifecycle of user, group, computer, and OU management, and they integrate with other Windows administration tools for deeper control.