Active Directory PowerShell commands cheat sheet
Everyday cmdlets from the ActiveDirectory PowerShell module, plus repadmin and dcdiag for domain health. Read-only commands work for any domain user; changes need the right delegated rights.
- Covers
- ActiveDirectory module on Windows Server 2016-2025 and RSAT for Windows 10/11
- Commands
- 50
- Last verified
Setup and domain info
| Command | What it does |
|---|---|
Add-WindowsCapability -Online -Name Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0 | Install the AD DS and AD LDS tools, including the ActiveDirectory module, on Windows 10 or 11. Run from an elevated PowerShell window. Get-WindowsCapability -Online | Where-Object Name -like 'RSAT*' lists every RSAT tool. |
Install-WindowsFeature -Name RSAT-AD-Tools -IncludeAllSubFeature | Install the AD DS and AD LDS management tools, including the module, on Windows Server. |
Import-Module ActiveDirectory | Load the ActiveDirectory module into the current session. PowerShell loads it automatically the first time you run an AD cmdlet; import it explicitly at the top of scripts. |
Get-ADDomain | Show the current domain, its functional level and the PDC emulator, RID master and infrastructure master. Example Get-ADDomain -Identity contoso.com |
Get-ADForest | Show the forest, its domains, global catalogs, functional level and schema and domain naming masters. Example Get-ADForest -Identity contoso.com |
Get-ADDomainController -Discover | Find a domain controller through the DC locator, optionally one offering a given service. Example Get-ADDomainController -Discover -Service "PrimaryDC"-Service "GlobalCatalog" finds a global catalog server; -ForceDiscover skips the cached result. |
Get-ADDomainController -Filter * | List every domain controller in the domain. Example Get-ADDomainController -Filter * | Select-Object Name,Site,IPv4Address,OperatingSystem |
Users
| Command | What it does |
|---|---|
Get-ADUser -Identity <user> -Properties * | Show every attribute of one user account. Example Get-ADUser -Identity jsmith -Properties *-Identity accepts a sAMAccountName, distinguished name, GUID or SID. Without -Properties only a small default set is returned. |
Get-ADUser -Filter <filter> | Find users that match a filter. Example Get-ADUser -Filter "Department -eq 'Sales'" -Properties Department,Title-Filter is required when you do not use -Identity; -Filter * returns every user. |
Get-ADUser -Filter * -SearchBase <OU-DN> | List the users in one OU and the OUs below it. Example Get-ADUser -Filter * -SearchBase "OU=Staff,DC=contoso,DC=com"-SearchScope OneLevel limits the search to that OU only. |
New-ADUser -Name <name> -SamAccountName <user> -AccountPassword <securestring> -Enabled $true | Create a user account with a password and enable it. Example New-ADUser -Name "Jane Smith" -GivenName Jane -Surname Smith -SamAccountName jsmith -UserPrincipalName [email protected] -Path "OU=Staff,DC=contoso,DC=com" -AccountPassword (Read-Host -AsSecureString "Password") -Enabled $true -ChangePasswordAtLogon $trueWithout -Enabled $true the account is created disabled, with or without a password. Without -Path it goes into the default Users container. |
Set-ADUser -Identity <user> -<Parameter> <value> | Change attributes on an existing user. Example Set-ADUser -Identity jsmith -Title "Sales Manager" -Department Sales -ChangePasswordAtLogon $trueFor attributes without their own parameter use -Replace @{attribute='value'}, -Add, -Remove or -Clear. |
Set-ADAccountPassword -Identity <user> -Reset -NewPassword <securestring> | Reset a user's password as an administrator. Example Set-ADAccountPassword -Identity jsmith -Reset -NewPassword (Read-Host -AsSecureString "New password")Follow with Set-ADUser -Identity jsmith -ChangePasswordAtLogon $true to force a change at next sign-in. |
Unlock-ADAccount -Identity <user> | Unlock an account that was locked out by failed sign-ins. Example Unlock-ADAccount -Identity jsmith |
Enable-ADAccount -Identity <user> | Enable a disabled user, computer or service account. Example Enable-ADAccount -Identity jsmith |
Disable-ADAccount -Identity <user> | Disable an account so it can no longer sign in. Example Disable-ADAccount -Identity jsmithSafer than deleting a leaver: the SID, group memberships and attributes stay intact if you need them back. |
Search-ADAccount -LockedOut | List accounts that are currently locked out. Example Search-ADAccount -LockedOut -UsersOnly | Select-Object Name,SamAccountName |
Search-ADAccount -AccountInactive -TimeSpan <days.hh:mm:ss> | Find accounts that have not signed in within a period. Example Search-ADAccount -AccountInactive -TimeSpan 90.00:00:00 -UsersOnly-DateTime uses a fixed date instead of a period. Requires Windows Server 2003 domain functional level or higher. |
Search-ADAccount -PasswordExpired | List accounts whose password has expired. Example Search-ADAccount -PasswordExpired -UsersOnly |
Search-ADAccount -PasswordNeverExpires | List accounts set so their password never expires, a common audit finding. Example Search-ADAccount -PasswordNeverExpires -UsersOnly |
Set-ADAccountExpiration -Identity <user> -DateTime <date> | Set the date an account stops working, for contractors and temporary staff. Example Set-ADAccountExpiration -Identity contractor01 -DateTime "2026-12-31" |
Remove-ADUser -Identity <user> | Delete a user account. Example Remove-ADUser -Identity jsmithWarning: The account, its SID and its group memberships are removed. Without the AD Recycle Bin you need an authoritative restore from backup to get it back. Prompts for confirmation by default. |
Groups
| Command | What it does |
|---|---|
Get-ADGroup -Filter <filter> | Find groups by name, scope or category. Example Get-ADGroup -Filter 'GroupCategory -eq "Security" -and Name -like "Sales*"'Use -Identity <group> -Properties member to read one group's member list. |
New-ADGroup -Name <name> -GroupScope <scope> -GroupCategory <category> | Create a security or distribution group. Example New-ADGroup -Name "Sales Team" -SamAccountName SalesTeam -GroupScope Global -GroupCategory Security -Path "OU=Groups,DC=contoso,DC=com"-GroupScope takes DomainLocal, Global or Universal; -GroupCategory takes Security or Distribution. |
Add-ADGroupMember -Identity <group> -Members <member>,<member> | Add users, computers or groups to a group. Example Add-ADGroupMember -Identity SalesTeam -Members jsmith,akumarUsers pick up a new security group membership at their next sign-in. |
Get-ADGroupMember -Identity <group> -Recursive | List the members of a group, including members of nested groups. Example Get-ADGroupMember -Identity "Domain Admins" -Recursive | Select-Object Name,objectClass-Recursive returns the users and computers at the end of the nesting chain, not the nested groups themselves. |
Remove-ADGroupMember -Identity <group> -Members <member> | Remove members from a group. Example Remove-ADGroupMember -Identity SalesTeam -Members jsmithWarning: The member loses any access granted through that group. Prompts for confirmation; scripts add -Confirm:$false. |
Get-ADPrincipalGroupMembership -Identity <user> | List the groups a user, computer or group is a member of. Example Get-ADPrincipalGroupMembership -Identity jsmith | Select-Object Name |
Computers
| Command | What it does |
|---|---|
Get-ADComputer -Filter <filter> | Find computer accounts and read properties such as OS and IP address. Example Get-ADComputer -Filter 'Name -like "SALES-*"' -Properties OperatingSystem,IPv4AddressUse -Identity <name> -Properties * to see everything about one computer. |
Search-ADAccount -AccountInactive -ComputersOnly -TimeSpan <days.hh:mm:ss> | Find computer accounts that have not signed in to the domain within a period. Example Search-ADAccount -AccountInactive -ComputersOnly -TimeSpan 90.00:00:00 |
Test-ComputerSecureChannel | Check the trust between this domain member and its domain; returns True or False. Example Test-ComputerSecureChannel -Server dc01.contoso.com -VerboseRun it on the member computer, not on a domain controller. Windows PowerShell 5.1 only. |
Test-ComputerSecureChannel -Repair -Credential <domain\user> | Repair a broken trust relationship without rejoining the domain. Example Test-ComputerSecureChannel -Repair -Credential CONTOSO\admin01The account needs permission to reset the computer account. Windows PowerShell 5.1 only. |
Reset-ComputerMachinePassword -Server <dc> -Credential <domain\user> | Reset the computer account password that this machine shares with the domain. Example Reset-ComputerMachinePassword -Server dc01.contoso.com -Credential CONTOSO\admin01Windows PowerShell 5.1 only. |
OUs, objects and the recycle bin
| Command | What it does |
|---|---|
New-ADOrganizationalUnit -Name <name> -Path <parent-DN> | Create an organizational unit. Example New-ADOrganizationalUnit -Name "Staff" -Path "DC=contoso,DC=com"New OUs are protected from accidental deletion unless you pass -ProtectedFromAccidentalDeletion $false. |
Move-ADObject -Identity <DN> -TargetPath <OU-DN> | Move a user, computer, group or OU to another OU. Example Move-ADObject -Identity "CN=Jane Smith,OU=Staff,DC=contoso,DC=com" -TargetPath "OU=Sales,DC=contoso,DC=com"Group Policy linked to the new OU applies from the next policy refresh. |
Set-ADObject -Identity <DN> -ProtectedFromAccidentalDeletion <bool> | Turn deletion protection on or off for an object. Example Set-ADObject -Identity "OU=Staff,DC=contoso,DC=com" -ProtectedFromAccidentalDeletion $falseA protected OU cannot be deleted or moved until protection is cleared. Turn it back on afterwards. |
Get-ADOptionalFeature -Identity 'Recycle Bin Feature' | Show the AD Recycle Bin feature and where it is enabled. |
Enable-ADOptionalFeature -Identity 'Recycle Bin Feature' -Scope ForestOrConfigurationSet -Target <forest> | Enable the Active Directory Recycle Bin for the forest. Example Enable-ADOptionalFeature -Identity 'Recycle Bin Feature' -Scope ForestOrConfigurationSet -Target contoso.comCannot be disabled once enabled. Needs Windows Server 2008 R2 forest functional level and Enterprise Admins rights. Objects deleted before you enable it can only come back from a backup. |
Get-ADObject -Filter <filter> -IncludeDeletedObjects | Find deleted objects, including ones in the Deleted Objects container. Example Get-ADObject -Filter 'samAccountName -eq "jsmith"' -IncludeDeletedObjects |
Restore-ADObject -Identity <object> | Restore a deleted object with its attributes and group memberships from the recycle bin. Example Get-ADObject -Filter 'samAccountName -eq "jsmith"' -IncludeDeletedObjects | Restore-ADObjectWorks only if the Recycle Bin was enabled before the object was deleted. -TargetPath restores to a different OU. |
Domain controller and replication health
| Command | What it does |
|---|---|
Get-ADReplicationPartnerMetadata -Target <dc> | Show replication partners of a DC with last success time and last result. Example Get-ADReplicationPartnerMetadata -Target dc01 -PartnerType InboundLastReplicationResult of 0 means success; also check ConsecutiveReplicationFailures. |
Get-ADReplicationPartnerMetadata -Target <domain> -Scope Domain | Show replication status for every DC in a domain. Example Get-ADReplicationPartnerMetadata -Target contoso.com -Scope Domain | Select-Object Server,Partner,LastReplicationSuccess,LastReplicationResult |
Get-ADReplicationFailure -Target <dc-or-domain> | List replication failures for a DC, site, domain or forest. Example Get-ADReplicationFailure -Target contoso.com -Scope Domain |
repadmin /replsummary | Summarize replication across domain controllers and flag the ones that are failing. Example repadmin /replsummary * /bysrc /bydest /sort:delta/errorsonly shows only DCs with partner errors. Installed with the AD DS tools. |
repadmin /showrepl <dc> | Show when a DC last tried inbound replication for each partition and whether it worked. Example repadmin /showrepl dc01 |
dcdiag /s:<dc> | Run the standard domain controller health tests against a DC. Example dcdiag /s:dc01 /q/q prints only errors, /v adds detail, /e tests every DC in the enterprise and /c runs the comprehensive set. |
dcdiag /test:DNS | Test DNS registration, forwarders and delegation for domain controllers. Example dcdiag /test:DNS /s:dc01 /v |
Password policy
| Command | What it does |
|---|---|
Get-ADDefaultDomainPasswordPolicy | Show the domain password and lockout policy: length, complexity, age and lockout threshold. Example Get-ADDefaultDomainPasswordPolicy -Identity contoso.com |
Get-ADFineGrainedPasswordPolicy -Filter * | List fine-grained password policies (PSOs) and their precedence. Example Get-ADFineGrainedPasswordPolicy -Filter * | Select-Object Name,Precedence,MinPasswordLength,AppliesTo |
Get-ADUserResultantPasswordPolicy -Identity <user> | Show which fine-grained password policy actually applies to a user. Example Get-ADUserResultantPasswordPolicy -Identity jsmithA PSO linked directly to the user wins over ones linked to groups; among groups the lowest precedence value wins. |
Official references
Last verified against these pages. Commands marked Warning restart, erase or remove something: run them only in a maintenance window and with a backup.
- Remote Server Administration Tools (RSAT) for Windows learn.microsoft.com
- New-ADUser (ActiveDirectory module) learn.microsoft.com
- Search-ADAccount (ActiveDirectory module) learn.microsoft.com
- Restore-ADObject (ActiveDirectory module) learn.microsoft.com
- Active Directory Recycle Bin and Administrative Center enhancements learn.microsoft.com
- Get-ADReplicationPartnerMetadata (ActiveDirectory module) learn.microsoft.com
- Repadmin /replsummary learn.microsoft.com
- dcdiag command reference learn.microsoft.com
Questions people ask
How do I install the Active Directory PowerShell module on Windows 11?
Open PowerShell as administrator and run Add-WindowsCapability -Online -Name Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0. On Windows Server use Install-WindowsFeature -Name RSAT-AD-Tools -IncludeAllSubFeature. The cmdlets are then available; Import-Module ActiveDirectory loads them explicitly.
How do I unlock an Active Directory account with PowerShell?
Find locked accounts with Search-ADAccount -LockedOut -UsersOnly, then run Unlock-ADAccount -Identity <username>. If the account locks again soon after, a phone, mapped drive, service or saved credential is probably still trying an old password.
How do I find inactive users in Active Directory?
Run Search-ADAccount -AccountInactive -TimeSpan 90.00:00:00 -UsersOnly to list user accounts with no sign-in in the last 90 days. Review the list before acting, and disable accounts with Disable-ADAccount rather than deleting them so they can be re-enabled if something breaks.
Can I restore a deleted Active Directory user?
Yes, if the AD Recycle Bin was enabled before the deletion: find the object with Get-ADObject -IncludeDeletedObjects and pipe it to Restore-ADObject, which brings back its attributes and group memberships. Without the Recycle Bin you need an authoritative restore from a system state backup. Enabling the Recycle Bin cannot be undone.