Active Directory (AD) management helps system administrators control user access and resources easily. It keeps the network safe and organized.
Why AD management is essential for sysadmins in PowerShell
Introduction
Syntax
PowerShell
Import-Module ActiveDirectory Get-ADUser -Identity username Set-ADUser -Identity username -Enabled $false
Use Import-Module ActiveDirectory to load AD commands in PowerShell.
Get-ADUser retrieves user details; Set-ADUser changes user properties.
Examples
PowerShell
Get-ADUser -Identity jsmith
PowerShell
Set-ADUser -Identity jsmith -Enabled $false
PowerShell
New-ADUser -Name "Jane Doe" -SamAccountName janed -AccountPassword (ConvertTo-SecureString "P@ssw0rd" -AsPlainText -Force) -Enabled $true
Sample Program
This script checks if the user 'jsmith' exists in Active Directory. If found, it disables the user account and prints confirmation messages.
PowerShell
Import-Module ActiveDirectory # Check if user 'jsmith' exists $user = Get-ADUser -Identity jsmith -ErrorAction SilentlyContinue if ($user) { Write-Output "User 'jsmith' found." # Disable the user account Set-ADUser -Identity jsmith -Enabled $false Write-Output "User 'jsmith' has been disabled." } else { Write-Output "User 'jsmith' does not exist." }
Important Notes
Always test AD commands in a safe environment before running on live systems.
Disabling a user is safer than deleting, as it preserves data and settings.
Use proper permissions to run AD management commands.
Summary
AD management helps control who can access network resources.
PowerShell makes managing AD users and settings easier and faster.
Regular AD management keeps the network secure and organized.
Practice
1. Why is Active Directory (AD) management important for system administrators?
easy
Solution
Step 1: Understand AD's role in access control
Active Directory manages who can access files, printers, and other resources on a network.Step 2: Recognize sysadmin responsibilities
Sysadmins use AD to set permissions and keep the network secure and organized.Final Answer:
It helps control user access to network resources. -> Option AQuick Check:
AD controls access = A [OK]
Hint: AD controls access rights for users and devices [OK]
Common Mistakes:
- Thinking AD slows down the network
- Believing AD removes security settings
- Assuming AD lets users install any software
2. Which PowerShell cmdlet is used to create a new Active Directory user?
easy
Solution
Step 1: Identify cmdlets for AD user management
New-ADUser creates users, Get-ADUser retrieves users, Remove-ADUser deletes users, Set-ADGroup modifies groups.Step 2: Match cmdlet to creation task
Creating a new user requires New-ADUser.Final Answer:
New-ADUser -> Option AQuick Check:
Create user cmdlet = New-ADUser [OK]
Hint: New-ADUser creates users; Get-ADUser only reads [OK]
Common Mistakes:
- Using Get-ADUser to create users
- Confusing Remove-ADUser with creation
- Using Set-ADGroup for user creation
3. What will this PowerShell command output?
Get-ADUser -Filter 'Enabled -eq $true' | Select-Object -ExpandProperty Name
medium
Solution
Step 1: Understand the filter condition
The filter 'Enabled -eq $true' selects only users whose Enabled property is true (active users).Step 2: Analyze the Select-Object usage
Select-Object -ExpandProperty Name extracts just the user names from the results.Final Answer:
List of all enabled user names -> Option DQuick Check:
Filter enabled users = list names [OK]
Hint: Filter Enabled -eq $true lists active users only [OK]
Common Mistakes:
- Thinking it lists disabled users
- Assuming it returns groups instead of users
- Believing the filter syntax causes error
4. Identify the error in this PowerShell snippet for disabling an AD user:
Disable-ADUser -Identity $userName
medium
Solution
Step 1: Check if Disable-ADUser exists
There is no Disable-ADUser cmdlet in PowerShell AD module; disabling is done with Set-ADUser.Step 2: Correct method to disable user
Use Set-ADUser -Identity $userName -Enabled $false to disable a user.Final Answer:
Disable-ADUser cmdlet does not exist. -> Option CQuick Check:
No Disable-ADUser cmdlet = A [OK]
Hint: Use Set-ADUser -Enabled $false to disable users [OK]
Common Mistakes:
- Assuming Disable-ADUser cmdlet exists
- Using wrong parameter names
- Thinking -Confirm is mandatory
5. A sysadmin wants to automate disabling all inactive AD users who haven't logged in for 90 days. Which PowerShell approach is best?
hard
Solution
Step 1: Identify how to find inactive users
Get-ADUser can filter users by LastLogonDate to find those inactive for 90 days.Step 2: Automate disabling users
Piping filtered users to Set-ADUser -Enabled $false disables them efficiently.Final Answer:
Use Get-ADUser with -Filter on LastLogonDate, then pipe to Set-ADUser -Enabled $false. -> Option BQuick Check:
Filter inactive users + disable = D [OK]
Hint: Filter inactive users by last logon, then disable in bulk [OK]
Common Mistakes:
- Disabling users manually one by one
- Removing users instead of disabling
- Using group membership instead of last logon date
Recommended
Ready to prove it?
Pass the test and this pattern moves unknown
10 questions ~5 mineasy hard
