Learn Active Directory Management in a Month of Lunches
A book by Richard Siddaway
PART 1 MANAGING ACTIVE DIRECTORY DATA
1 Before you begin
1.1 AD core deliverables
1.1.1 Authentication
You’re logging on to the domain, not an individual computer.
Active Directory uses the Kerberos protocol for authentication.
Time synchronization within your Active Directory is important because the time stamp is used during the authentication process.
1.1.2 Authorization
Authorization is the act of granting users appropriate access to resources—such as file shares, databases, applications, and mailboxes—once they’ve authenticated themselves to Active Directory. The concept of authorization is simply one of proving you have permission to do something.
To simplify the process, when you log on a token is created on your local machine that contains your group memberships, privileges, and rights. This is presented to resources that you’re trying to access. The system will check the token to see if your permissions allow you access to the file or other resource, and either grant or deny access based on the data presented in your token.
1.1.3 AD definitions
FOREST
The forest is the whole of your Active Directory. It can contain one or more domains arranged in trees (that’s why it’s called a forest). The forest is named after the first domain created in the forest (known as the root domain, which can’t be changed).
All domains in a forest share a common Configuration container and a common schema.
The domains are linked together by transitive trusts that are automatically created when the domains are created.
DOMAIN
A domain is a container for the objects you’ll work with—users, computers, groups, and so on.
The domain provides a number of boundaries within the organization:
It’s an administration boundary. Domain administrators don’t have permissions in other domains.
It’s a security administration boundary. Permissions applied within the domain can’t affect objects outside the domain.
It’s a policy application boundary. Best practice is to limit the application of Group Policy to a single domain. Applying policies across domains will slow processing and make administration much harder.
A domain has a fully qualified Domain Name System (
DNS) name as its unique identifier.
Domains can be arranged in a hierarchy (trees) with parent-child relationships.
ORGANIZATIONAL UNIT
An organizational unit (OU) is a container within a domain that can be used to hold user, computer, group, and other OU objects.
There are two main reasons to create an OU:
1 To control the delegation of administrative privileges (a certain group of administrators can only control the users, groups, and computers in a certain OU).
2 To control the application of Group Policy.
Containers
There are a number of these, but the ones you’re most likely to come across are
Built-in, which stores a number of the default groups.
Users, which stores other default groups, especially the Domain Admins, Enterprise Admins, and Schema Admins. It’s also the default location for the creation of new users if a specific OU isn’t given.
Computers, which is empty when the domain is created but is the default location for the creation of computer accounts when a new machine is joined to the domain.
The major differences between a container and an OU are that Group Policy cannot be applied to a container and child OUs can’t be created within a container.
NOTE
Think of the AD structures outlined in this section as analogous to a Russian nesting doll. Forests contain domains, which contain OUs, which contain users, groups, and computers.
1.2 Is this book for you?
1.3 How to use this book
1.4 Creating your lab environment
2 Creating user accounts
Computer accounts are a specialized form of user account. In most organizations they’re put into separate organizational units (OUs) to make the Group Policy Object (GPO) application simpler.
IDEA: - make user groups to make administration of GPOs for our OUs simpler.
2.1 Creating new user accounts
2.1.1 Creating a new user with ADAC
2.1.2 Creating a new user with ADUC
2.1.3 Creating a new user with PowerShell
The following code can be used to create a new user:
$secpass = Read-Host "Password" -AsSecureString
New-ADUser -Name "GREEN Dave" -SamAccountName dgreen
➥ -UserPrincipalName "dgreen@manticore.org" -AccountPassword $secpass
➥ -Path "cn=Users,dc=Manticore,dc=org" -Enabled:$true
2.2 User creation from a template
One way to reduce the amount of work you need to perform and reduce the chance of an error occurring is to use a template. This is a fully configured account that’s copied to form a new account.
The usual starting point is to create each new user account from scratch. This can be performed using
GUI tools or PowerShell. One alternative, used in many organizations, is to use a template from which to create new user accounts. The template could be a standard user account or a specially created account that’s used only as a template.
$secpass = Read-Host "Password" -AsSecureString
$user = Get-ADUser -Identity jgreen -Properties memberof, office
New-ADUser -Name "GREEN Bill" -SamAccountName bgreen
➥ -UserPrincipalName "bgreen@manticore.org"
➥ -AccountPassword $secpass -Path "cn=Users,dc=Manticore,dc=org"
➥ -Enabled:$true -Instance $user
2.3 User creation in bulk
$secpass = Read-Host "Password" -AsSecureString
Import-Csv names.csv |
foreach {
$name = "$($_.LastName) $($_.FirstName)"
New-ADUser -GivenName $($_.FirstName) -Surname $($_.LastName) `
-Name $name -SamAccountName $($_.SamAccountName) `
-UserPrincipalName "$($_.SamAccountName)@manticore.org" `
-AccountPassword $secpass -Path "cn=Users,dc=Manticore,dc=org" `
-Enabled:$true
}
2.4 Creating managed service accounts
Managed service accounts are used to run services such as SQL Server, Exchange, and IIS on systems within your domain.
The recommended approach is to use the New-ADServiceAccount PowerShell cmdlet.
… (not really important for me at this time)
2.5 Lab
… (not really important for me at this time)
2.6 Ideas for on your own
3 Managing user accounts
User account management can be summed up as CRUD (create, read, update, delete).
3.1 Modifying user account properties
3.1.2 Using PowerShell to modify user accounts
Set-ADUser -Identity "CN=GREEN Bill,CN=Users,DC=Manticore,DC=org" `
-OfficePhone "01234 567895"
Set-ADUser -Identity "CN=GREEN Bill,CN=Users,DC=Manticore,DC=org" -Replace @{otherTelephone="01234 567896","01234 567897"}
When you use the Add, Remove, Replace, and Clear parameters together, the operations will be performed in the following order:
1 Remove
2 Add
3 Replace
4 Clear
3.1.3 Copying attributes from another account
Copying attributes with GUI tools is a bit long-winded, and you’ll soon get bored if you have to do this for a number of users.
A little bit of PowerShell can make your life much easier:
$source = Get-ADUser -Identity bgreen -Properties OfficePhone, otherTelephone
Set-ADUser -Identity "CN=GREEN Dave,CN=Users,DC=Manticore,DC=org"
➥ -OfficePhone $($source.OfficePhone)
➥ -Replace @{otherTelephone = $($source.otherTelephone)}
3.2 Enabling or disabling user accounts
Disable with PowerShell:
Disable-ADAccount -Identity dgreen
Enable with PowerShell:
Enable-ADAccount -Identity dgreen
3.3 Deleting user accounts
Remove-ADUser -Identity dgreen -Confirm:$false
Leave off the -Confirm:$false if you want a message to force you to confirm the action. Not a bad idea with deletes!
3.4 Lab
3.5 Ideas for on your own
4 Managing groups
AD groups are objects that act as containers for users, computers, and other groups. Groups are used to make the management of users easier, especially when it comes to granting permissions to access resources. … For now, just remember that you should apply permissions to groups, not users.
4.1 Group types
4.2 Group lifecycle
4.2.1 Creating groups
You can create a group using the
GUI tools or with PowerShell. You need the following information to create a group:
New-ADGroup -Name PStest -Path "CN=Users,DC=Manticore,DC=org"
➥ -GroupCategory Security -GroupScope Global
➥ -Description "Test group for AD Lunches"
4.2.2 Changing group scope
Changing a group’s scope is slightly more complicated because there are a number of restrictions on the possible changes, as shown in table 4.3.
A Universal group can be changed to a Global or Domain Local group, as shown in table 4.3. A Global group can’t be changed into a Domain Local group directly — it has to first be made into a Universal group. Changing from a Domain Local to a Global group also has to be via a Universal group.
Set-ADGroup -Identity ADL-group1 -GroupScope Universal
Set-ADGroup -Identity ADL-group3 -GroupScope Universal
Set-ADGroup -Identity ADL-group3 -GroupScope DomainLocal
4.2.3 Deleting a group
Remove-ADGroup -Identity ADL-Test3 -Confirm:$false
4.3 Managing group membership
In
GUI tools, the group membership dialog is accessed by right-clicking the group and choosing Properties.
4.3.2 Using PowerShell to manage group membership
Get-ADGroupMember -Identity ADL-group1 | select Name, DistinguishedName
Add-ADGroupMember -Identity ADL-group1 -Members "CN=GREEN Bill,CN=Users,DC=Manticore,DC=org"
# Remember, you can search for the user to add to the group:
Add-ADGroupMember -Identity ADL-group1 -Members (Get-ADUser -LDAPFilter "(Name=Green Bill)")
Remove-ADGroupMember -Identity ADL-group1 -Members bgreen -Confirm:$false
4.4 Lab
4.4.1 Complete the TRY IT NOW sections
4.4.2 Create six new groups
4.4.3 Change group scope
4.4.4 Add group members
4.4.5 Remove a user from group
4.4.6 Nest groups
4.4.7 Delete user account
4.4.8 Add computer account to group
4.5 Ideas for on your own
In many organizations there isn’t a naming convention for groups—think about establishing one if your organization doesn’t have one.
If your groups don’t have descriptions, think about adding them as you’re working with individual groups.
Don’t sit and do all groups in one pass. Add them as you manage them.
An activity that comes up from time to time is copying the group membership from one user to another. How could you do that?
5 Troubleshooting users and groups
5.1 Troubleshooting first steps
5.1.1 Step 1: Is the account disabled?
the user.
# This code will display a list of disabled accounts.
Search-ADAccount -AccountDisabled | select Name, samAccountName
# If your user is in the list, enable the account like this:
Get-ADUser -Identity dgreen | Enable-ADAccount
5.1.2 Step 2: Check account status
5.1.3 Step 3: Has the account expired?
Search-ADAccount -AccountExpired | Format-Table Name, SamAccountName, DistinguishedName, AccountExpirationDate -AutoSize
Get-ADUser -Identity dgreen | Set-ADAccountExpiration -DateTime (Get-Date).AddDays(30)
# Alternatively, you could set a specific date using code like this:
Get-ADUser -Identity dgreen | Set-ADAccountExpiration -DateTime ([datetime]'11/25/2013')
# WARNING: If you use this technique, the date must be presented as month/day/year.
Get-ADUser -Identity dgreen | Clear-ADAccountExpiration
5.2 Password expiry
Neither of the
GUI tools supply a direct way to see if the password has expired.
Search-ADAccount -PasswordExpired
5.3 Password reset
$password = Read-Host -Prompt "Password" -AsSecureString
$id = "dgreen"
Set-ADAccountPassword -Identity $id -NewPassword $password -Reset
Set-ADUser -Identity $id -ChangePasswordAtLogon:$true
5.4 Unlocking a user account
5.5 Group membership
$target = Get-ADUser -Identity mgreen -Properties memberof
foreach ($member in $target.memberof){
Remove-ADGroupMember -Identity $member -Members $target -Confirm:$false
}
$source = Get-ADUser -Identity dgreen -Properties memberof
foreach ($member in $source.memberof){
Add-ADGroupMember -Identity $member -Members $target -Confirm:$false
}
5.6 Lab
5.6.1 Complete any TRY IT NOW sections
5.6.2 Account expiry
5.6.3 Account lockout
5.6.4 Disable an account
5.7 Ideas for on your own
6 Managing computer accounts
6.1 Creating an AD computer account
6.1.1 Creating a computer account using ADAC
6.1.2 Creating a computer account using ADUC
6.1.3 Creating a computer account using PowerShell
New-ADComputer -Enabled $true -Name ADLComp3 `
-Path "CN=Computers,DC=Manticore,DC=org" `
-SamAccountName ADLCOMP3
6.2 Joining a computer to the domain
6.2.1 Using GUI tools to join a machine to the domain
6.2.2 Using PowerShell to join a machine to the domain
$cred = Get-Credential
Add-Computer -Credential $cred -DomainName Manticore `
-OUPath "OU=Security Servers,OU=Servers,DC=Manticore,DC=org" -Force
Restart-Computer
6.3 Managing the secure channel
All computers (Windows 2000 and later) in an AD domain communicate with a domain controller. They authenticate over that channel every time the machine is restarted.
A password is used to authenticate the machine. This password is automatically reset every 30 days—you don’t have to do anything, it just happens. The secure channel is a robust mechanism and usually doesn’t go wrong.
A simpler approach to test secure channel is to use the PowerShell that the secure channel is the cause of the problem is the Test-ComputerSecure-Channel cmdlet.
You can test and fix in one go:
if (-not(Test-ComputerSecureChannel)){
Test-ComputerSecureChannel -Repair –Verbose
}
6.4 Deleting a computer account
Search-ADAccount -AccountInactive -ComputersOnly | Format-Table Name, DistinguishedName, LastLogonDate, ObjectClass -Autosize
Search-ADAccount -AccountInactive -ComputersOnly -TimeSpan "90:00:00"|
where ObjectClass -eq "Computer" |
Format-Table Name, DistinguishedName, LastLogonDate, ObjectClass -Autosize
Import-Csv -Path C:\Scripts\ADLunches\computersTodelete.txt |
foreach {
Remove-ADComputer -Identity $_.Name -Confirm:$false
}
6.5 Lab
6.5.1 Create computer accounts
6.5.2 Create computer accounts in bulk
6.5.3 Searching for computer accounts
6.5.4 Managing the secure channel
6.5.5 Deleting computer accounts
6.6 Ideas for on your own
Use the scripts in this chapter to create a mechanism for removing expired accounts. Hint: make it a two-stage process to find the expired accounts and examine them to determine which to delete. Then perform the deletion.
Create a process for the bulk creation of computer accounts.
Create a script that tests the service-pack level of your computers. You can then proactively start reporting which machines need to be service packed.
7 Managing organizational units
7.1 OU concepts
An OU is a container within a domain that can be used to hold user, computer, group, and other OU objects.
7.2.1. Creating an OU with ADAC
7.2.2 Creating an OU with ADUC
7.3 Creating an OU with PowerShell
7.4 Protecting OUs from accidental deletion
7.5 Managing OUs
Renaming an OU 84 ■ Adding a description to the OU 84
Changing the Managed By setting 85 ■ Deleting an OU 86
xii CONTENTS
7.6 Moving objects between OUs
7.7 Lab
Creating OUs 88 ■ Renaming OUs 88 ■ Setting
descriptions and Managed By 89 ■ Moving objects between
OUs 89 ■ Deleting an OU 90
7.8 Ideas for on your own
PART 2 MANAGING GROUP POLICY
8 Creating Group Policies
9 Managing Group Policies
10 Fine-grained password policies
PART 3 MANAGING THE ACTIVE DIRECTORY SERVICE
11 Creating domain controllers
12 Managing domain controllers
13 Protecting AD data
14 Security: Default groups and delegation
15 Managing DNS
16 Managing sites and subnets
17 AD replication
18 Managing AD trusts
PART 4 MAINTENANCE AND TROUBLESHOOTING
19 Troubleshooting your AD
20 Maintaining and monitoring Active Directory
21 Future work and final exam
22 Into the cloud
MY NOTES