PowerShell Commands

If you’ve spent any serious time administering Active Directory, you’ve probably lived inside Active Directory Users and Computers (ADUC). For one-off tasks, the GUI is perfectly fine. But once you’re managing hundreds or thousands of users, multiple OUs, or recurring admin tasks, ADUC quickly becomes a bottleneck.

This is where PowerShell stops being “nice to have” and becomes essential.

In real enterprise environments — especially hybrid or legacy-heavy ones — PowerShell allows you to:

  • Perform bulk changes safely and consistently
  • Automate repetitive help desk tasks
  • Reduce human error caused by manual GUI actions
  • Audit and report on AD in ways ADUC simply can’t
  • Scale administration without scaling headcount

From my experience, the moment you’re asked to “disable 200 users by Friday” or “find all stale accounts across five OUs,” the GUI stops being practical.


Preparing Your Environment: Installing the Active Directory PowerShell Module

Before you can manage Active Directory with PowerShell, you need the Active Directory module.

Where the Module Comes From

  • Domain Controllers: Installed by default
  • Member servers / admin workstations: Requires RSAT (Remote Server Administration Tools)

On Windows 10/11 (modern builds), install RSAT via Optional Features rather than downloading a standalone installer.

Once RSAT is installed, load the module:

Import-Module ActiveDirectory

To confirm it’s available:

Get-Command -Module ActiveDirectory

You’ll see hundreds of cmdlets — don’t let that overwhelm you. In practice, most admins rely on 20–30 core commands day-to-day.


Understanding Identity: Distinguished Names vs SamAccountName

One mistake I see frequently is admins overusing Distinguished Names (DNs) when they don’t need to.

While this works:

-Identity "CN=Johnathan.Brown,OU=Accounts,DC=mydomain,DC=com"

It’s usually cleaner (and safer) to use:

  • SamAccountName
  • UserPrincipalName
  • Object GUID

Example:

Get-ADUser -Identity JBrown

Using shorter identities reduces errors and makes scripts more portable across environments.


Resetting User Passwords (Without Breaking Policy)

Password resets are still one of the most common help desk tasks.

Basic reset example:

Set-ADAccountPassword `
-Identity JBrown `
-Reset `
-NewPassword (ConvertTo-SecureString "TempP@ssw0rd!" -AsPlainText -Force)

In production environments, I strongly recommend pairing this with:

Set-ADUser JBrown -ChangePasswordAtLogon $true

Real-World Tip

Avoid hardcoding passwords in scripts wherever possible. If you must, restrict access tightly and rotate scripts regularly. For service desks, interactive prompts or password vault integration is far safer.


Disabling and Enabling Accounts for Offboarding and Leave

Account lifecycle management is an area where PowerShell shines.

Disable a user:

Disable-ADAccount -Identity JBrown

Re-enable:

Enable-ADAccount -Identity JBrown

Why PowerShell Beats the GUI Here

In real offboarding scenarios, disabling the account is often just step one. PowerShell makes it trivial to chain actions:

  • Disable account
  • Remove group memberships
  • Move user to a “Disabled Users” OU
  • Log the action

That entire workflow can be scripted and standardised.


Unlocking Locked Accounts Instantly

Locked accounts generate noise — and often frustration — on busy service desks.

Unlocking via PowerShell is immediate:

Unlock-ADAccount -Identity JBrown

Pro Tip

Pair this with a quick lockout audit:

Get-ADUser JBrown -Properties LockedOut

If accounts are locking repeatedly, the problem is usually cached credentials, mobile devices, or old mapped drives — not the user.


Safely Removing Users (and Avoiding Costly Mistakes)

Deleting user accounts is irreversible, which is why PowerShell’s -WhatIf parameter is invaluable.

Single user removal:

Remove-ADUser -Identity JBrown

Bulk Cleanup of Disabled, Inactive Accounts

This is where PowerShell becomes truly powerful:

Get-ADUser -Filter "Enabled -eq 'false'" `
-Property WhenChanged `
-SearchBase "OU=Employees,DC=mydomain,DC=com" |
Where-Object { $_.WhenChanged -le (Get-Date).AddDays(-180) } |
Remove-ADUser -WhatIf

Real-World Advice

Always run bulk deletions with -WhatIf first. I’ve seen production outages caused by one incorrect OU path.


Finding and Cleaning Up Empty AD Groups

Unused groups are a hidden security risk — especially when legacy permissions linger.

Find Empty Groups

Get-ADGroup -Filter * |
Where-Object { -not (Get-ADGroupMember $_ -ErrorAction SilentlyContinue) } |
Select Name

Targeted Cleanup (Universal Groups Only)

Get-ADGroup `
-Filter "members -notlike '*' -AND GroupScope -eq 'Universal'" `
-SearchBase "OU=Groups,OU=Employees,DC=mydomain,DC=com" |
Select Name, GroupScope

Why This Matters

Empty groups often:

  • Indicate incomplete decommissioning
  • Cause confusion during audits
  • Inflate attack surface unnecessarily

Cleaning them up improves both security and manageability.


Managing Group Memberships at Scale

Add a user to a group:

Add-ADGroupMember -Identity "BrisbaneLionsTeam" -Members JBrown

Add multiple users:

Add-ADGroupMember -Identity "ProjectX" -Members JBrown, SSmith, TNguyen

View group membership:

Get-ADGroupMember -Identity "Domain Admins"

Expert Insight

When auditing privileged groups like Domain Admins, always review nested groups. PowerShell exposes this instantly, whereas ADUC often hides it.


Reporting and Auditing: Where PowerShell Really Wins

PowerShell isn’t just about changes — it’s about visibility.

Examples:

  • Users who haven’t logged in for 90 days
  • Accounts with non-expiring passwords
  • Privileged users outside expected OUs
  • Service accounts without documentation

These aren’t edge cases — they’re daily realities in mature environments.


Building Confidence with PowerShell in Production

If you’re new to PowerShell, here’s practical advice from the field:

  • Start with read-only commands (Get-*)
  • Always test scripts in non-production OUs
  • Use -WhatIf and -Confirm
  • Comment scripts like someone else will maintain them (because they will)

PowerShell doesn’t replace good admin practices — it amplifies them.


Final Thoughts: PowerShell Is No Longer Optional for AD Admins

Modern Active Directory administration demands speed, consistency, and auditability. PowerShell delivers all three.

Once you move beyond one-off GUI clicks, there’s no going back. Whether you’re on a service desk, managing enterprise AD, or transitioning into security-focused roles, PowerShell skills pay dividends fast.

It’s no longer a question of whether you’ll manage Active Directory with PowerShell — only how long you’ll wait before fully embracing it.

Leave a Reply

Your email address will not be published. Required fields are marked *