Active Directory (AD) is the phone book and the gatekeeper of a Windows network. It stores who the users and computers are, which groups they belong to, and – through those groups – what they’re allowed to do.
Lab: promote a test VM to a domain controller for a new forest such as
contoso.local, or use your company’s test domain if you have rights there. Never practise on production AD.
The building blocks
| Term | What it is |
|---|---|
| Domain | A boundary of users, computers and policies, e.g. contoso.local |
| Domain controller (DC) | A server that runs AD and answers logon requests. Have at least two |
| Forest | One or more domains that trust each other |
| OU (organizational unit) | A folder for objects, used to delegate admin rights and link Group Policy |
| User / computer object | An account that can sign in |
| Group | A list of members used to give permissions |
OU vs group confuses everyone at first:
- An OU decides where an object lives – and therefore which Group Policies apply and who can manage it.
- A group decides what its members can access. One user is in one OU, but can be in many groups.
Group types and scopes
- Security groups give permissions. Distribution groups are only for email lists.
- Scope, simplified: use Global groups for people (e.g. GG-Finance-Users) and Domain Local groups for permissions on a resource (e.g. DL-FinanceShare-Read). Put the global group inside the domain local group, and give the domain local group the permission. This pattern (often called AGDLP) keeps permissions tidy as the company grows.
Tools
- Active Directory Users and Computers (
dsa.msc) – the classic console - Active Directory Administrative Center – newer, shows the PowerShell it runs
- PowerShell ActiveDirectory module – part of RSAT; on a DC it’s already installed
Import-Module ActiveDirectory
Get-ADDomain | Select-Object Name, DNSRoot, PDCEmulator
Everyday tasks in PowerShell
Find a user:
Get-ADUser -Identity jdoe -Properties LockedOut, PasswordLastSet, LastLogonDate, Enabled
Get-ADUser -Filter "Surname -eq 'Doe'" | Select-Object Name, SamAccountName
Create a user (prompts for the password, so it never appears in your script or history):
New-ADUser -Name 'Jane Doe' -GivenName Jane -Surname Doe `
-SamAccountName jdoe -UserPrincipalName jdoe@contoso.local `
-Path 'OU=Users,OU=Lab,DC=contoso,DC=local' `
-AccountPassword (Read-Host 'Initial password' -AsSecureString) `
-ChangePasswordAtLogon $true -Enabled $true
Unlock and reset:
Unlock-ADAccount -Identity jdoe
Set-ADAccountPassword -Identity jdoe -Reset -NewPassword (Read-Host 'New password' -AsSecureString)
Set-ADUser -Identity jdoe -ChangePasswordAtLogon $true
Groups:
Add-ADGroupMember -Identity 'GG-Finance-Users' -Members jdoe
Get-ADPrincipalGroupMembership -Identity jdoe | Select-Object Name
Get-ADGroupMember -Identity 'GG-Finance-Users' -Recursive | Select-Object Name
Disable a leaver (disable first, delete later – deleting can’t be undone easily):
Disable-ADAccount -Identity jdoe
Move-ADObject -Identity (Get-ADUser jdoe).DistinguishedName -TargetPath 'OU=Disabled,OU=Lab,DC=contoso,DC=local'
Useful reports
# Locked-out accounts right now
Search-ADAccount -LockedOut | Select-Object Name, SamAccountName
# Users who haven't signed in for 90 days
Search-ADAccount -AccountInactive -TimeSpan 90.00:00:00 -UsersOnly |
Select-Object Name, LastLogonDate | Sort-Object LastLogonDate
LastLogonDate is replicated roughly every 9–14 days, so it’s good for “inactive for months”, not for “did they log in this morning”.
Good habits
- Use separate admin accounts for admin work; never browse or read email as a domain admin.
- Turn on the AD Recycle Bin (
Enable-ADOptionalFeature) in your lab and at work if it’s off – it makes deleted objects recoverable. - Name groups consistently so their purpose is obvious from the name.
- Make bulk changes with
-WhatIffirst.
FAQ
Why can’t a user log in even after I unlocked them?
Check whether the account is disabled, expired, or the password must change at logon on a system that can’t prompt for it. Get-ADUser jdoe -Properties * shows all of these.
Should I delete users when they leave? Disable and move them first, keep them for an agreed period, then delete. That keeps file ownership and audit trails readable.
What’s next
Next: DNS and DHCP essentials – AD can’t work without DNS.
Practise this topic
Test yourself with free questions on this topic – instant answers and explanations.
Start practice questionsActive DirectoryWindows ServerPowerShellBeginnerIdentity