index
int64 0
4.08k
| text
stringlengths 34
4.9k
⌀ | url
stringclasses 38
values |
|---|---|---|
296
|
2. In the top-left pane, click the tree view icon.
3. Expand the System container.
4. Scroll down and right-click Password Settings Container, expand the New menu,
and then click Password Settings.
5. Fill in the desired password settings in the top pane. Note that the fields with a red
asterisk are required fields.
6. In the Directly Applies To section, click the Add button to add a security group that
will be the target of the FGPP.
7. Click OK to create the FGPP.
Using a command-line interface
The following will add the Marketing group to the list of groups that a PSO will apply
to:
psomgr -applyto cn=Marketing,cn=Users,dc=ADATUM,dc=COM -pso TestPSO -forreal
Using PowerShell
To add a group to the list of groups that a FGPP will apply to, use the following syntax:
Add-ADFineGrainedPasswordPolicySubject -Identity "<Name of FGPP>"↵
-Subjects "<Security Group sAMAccountName>"
Discussion
Once a PasswordSettingsObject has been created, you can modify the password and
account lockout settings controlled by the object, as well as the users and groups that
the PSO should apply to. Since the PasswordSettingsObject is an Active Directory
object class, these modifications can be made using any interface that can modify objects.
When working from the command line, the psomgr tool allows you to modify one or
multiple PSOs at a time, and can also create “starter” PSOs using the -quickstart
command-line switch. The full syntax for psomgr.exe can be obtained by typing
psomgr.exe /? at a command prompt or by visiting the joeware website.
See Also
“AD DS Fine-Grained Password and Account Lockout Policy Step-by-Step Guide”
7.15. Applying a Fine-Grained Password Policy to a Group Object | 271
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
297
| null |
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
298
|
CHAPTER 8
Computer Objects
8.0. Introduction
As far as Active Directory is concerned, computers are very similar to users. In fact,
computer objects inherit directly from the user object class, which is used to represent
user accounts. This means that computer objects possess all of the attributes of user
objects and then some. Computers need to be represented in Active Directory for many
of the same reasons users do, including the need to access resources securely, utilize
GPOs, and have permissions assigned to them.
To participate in a domain, computers need a secure channel to a domain controller. A
secure channel is an authenticated connection that can transmit encrypted data. To set
up the secure channel, a computer must present a password to a domain controller.
Similar to the way in which it authenticates a user account, Active Directory will use
Kerberos authentication to verify the identity of a computer account. Without the com
puter object and, by association, the password stored with it that the operating system
changes behind the scenes on a regular basis, there would be no way for the domain
controller to verify a computer is what it claims to be.
The Anatomy of a Computer
The default location for computer objects in a domain is the cn=Computers container
located directly off the domain root. You can, however, create computer objects any‐
where in a domain. You can also modify the default location for computer objects as
described in Recipe 8.13. Table 8-1 contains a list of some of the interesting attributes
that are available on computer objects.
273
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
299
|
Table 8-1. Attributes of computer objects
Attribute Description
cn Relative distinguished name of computer objects.
dnsHostName Fully qualified DNS name of the computer.
lastLogonTimestamp The approximate timestamp of the last time the computer logged in to the domain.
managedBy The distinguished name (DN) of the user or group that manages the computer.
memberOf List of DNs of the groups the computer is a member of.
msDSAuthenticatedToAccount
List
This attribute was introduced in Windows Server 2008. It is a backlink attribute that identifies
users who have successfully authenticated to a full DC via a particular RODC.
msDSIsPrimaryComputerFor
This attribute was introduced in Windows Server 2012. It indirectly identifies the primary
user of a computer.
msDS-RevealedUsers This attribute was introduced in Windows Server 2008. It identifies the list of users and
computers whose secrets have been replicated to an RODC.
operatingSystem Text description of the operating system running on the computer. See Recipe 8.14 for more
information.
operatingSystemHotFix Currently not being used, but will hopefully be populated at some point.
operatingSystemService
Pack
Service pack version installed on the computer. See Recipe 8.14 for more information.
operatingSystemVersion Numeric version of the operating system installed on the computer. See Recipe 8.14 for more
information.
pwdLastSet Large integer that can be translated into the last time the computer’s password was set. See
Recipe 8.10 for more information.
sAMAccountName NetBIOS-style name of the computer. This is typically the name of the computer with a $ at
the end.
userAccountControl Account flag that defines various account properties. In the case of a computer object, this
specifies whether the computer is a member computer or a domain controller.
8.1. Creating a Computer
Problem
You want to create a computer account.
Solution
Using a graphical user interface
1. Open the Active Directory Administrative Center.
2. In the left pane, click to highlight the desired domain.
274 | Chapter 8: Computer Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
300
|
3. In the right pane, click New and then click Computer.
4. Type a name for the computer, fill in the desired optional fields, and then click OK
to create the computer object.
Using a command-line interface
You can create a computer object using either the built-in DSAdd utility or AdMod. To
create an account using DSAdd, use the following syntax:
> dsadd computer "<ComputerDN>" -desc "<Description>"
To create a computer account using AdMod, enter the following:
> admod -b "<ComputerDN>" objectclass::computer↵
sAMAccountName::<ComputerName>$ userAccountControl::4096↵
description::"<Description>" -add
Using PowerShell
To create a computer account using PowerShell, use the new-ADComputer cmdlet as
follows:
New-ADComputer -Name "<ComputerName>" -SamAccountName "<SamAccountName>"↵
-Path <OU DN>
Discussion
Creating a computer object in Active Directory is not much different from creating a
user object. We set the description attribute in the CLI solutions, but it is not a
mandatory attribute. The only mandatory attribute is sAMAccountName, which should
be set to the name of the computer with a $ appended. Note that ADAC and ADUC will
both populate the sAMAccountName automatically based on the name given to the com‐
puter during the creation process. Also note that these solutions simply create a com
puter object. This does not mean any user can join a computer to the domain with that
computer account. For more information on creating a computer object and allowing
a specific user or group to join the computer to the domain, see Recipe 8.2.
See Also
Recipe 8.2 for creating a computer for a user; “New-ADComputer”; MSDN:
ADS_USER_FLAG_ENUM
8.1. Creating a Computer | 275
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
301
|
8.2. Creating a Computer for a Specific User or Group
Problem
You want to create a computer account for a specific user or group to join to the domain.
This requires setting permissions on the computer account so that the user or group
can modify certain attributes.
Solution
Using a graphical user interface
1. Open the Active Directory Administrative Center.
2. In the left pane, click to highlight the desired domain.
3. In the right pane, click New and then click Computer.
4. Type a name for the computer and fill in the desired optional fields.
5. In the top-right corner of the Computer section, click the Change button near the
text that says, “The above user or group can join this computer to a domain.”
6. Use the Object Picker to select a user or group to join the computer to the domain
and then click OK.
7. Click OK to create the computer object.
Using a command-line interface
In the following solution, replace <ComputerDN> with the distinguished name of the
computer object and <UserOrGroup> with the user principal name or NT-style name of
a user or group you want to manage the computer:
> dsadd computer <ComputerDN>
> dsacls <ComputerDN> /G <UserOrGroup>:CALCGRSDDTRC;;
> dsacls <ComputerDN> /G <UserOrGroup>:WP;description;
> dsacls <ComputerDN> /G <UserOrGroup>:WP;sAMAccountName;
> dsacls <ComputerDN> /G <UserOrGroup>:WP;displayName;
> dsacls <ComputerDN> /G <UserOrGroup>:WP;userAccountControl;
> dsacls <ComputerDN> /G <UserOrGroup>:WS;"Validated write to service↵
principalname";
> dsacls <ComputerDN> /G <UserOrGroup>:WS;"Validated write to DNS host name";
You can replace the first line of this code with the AdMod code from
Recipe 8.1 if you choose.
276 | Chapter 8: Computer Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
302
|
Discussion
By default, members of the Authenticated Users group can join up to 10 computers to
an Active Directory domain. If you’ve modified this default behavior or need to allow
a user to add computers to the domain on a regular basis, you need to grant certain
permissions so that the user has rights to modify the computer object. When you create
a computer via ADAC or the ADUC snap-in (dsa.msc), you have the option to select a
user or group to manage the computer object and join a computer to the domain using
that object. When you use that method, eight ACEs are added to the ACL of the computer
object. They are:
• List Contents, Read All Properties, Delete, Delete Subtree, Read Permissions, All
Extended Rights (i.e., Allowed to Authenticate, Change Password, Send As, Receive
As, Reset Password)
• Write Property for description
• Write Property for sAMAccountName
• Write Property for displayName
• Write Property for Logon Information
• Write Property for Account Restrictions
• Validated write to DNS hostname
• Validated write for service principal name
Using a graphical user interface
If you want to modify the default permissions that are applied when you select a user
or group through the GUI, double-click on the computer object after you’ve created it
and go to the Security tab. For the Security tab to be visible, you have to select
View→Advanced Features.
Using a command-line interface
With the dsacls utility, you can specify either a UPN (user@domain) or a down-levelstyle (DOMAIN\user) account name when applying permissions. Also, dsacls requires
that the displayName of the attribute, property set, or extended right you are setting the
permission on be used instead of the lDAPDisplayName, as you might expect. That is
why we had to use “Validated write to service principal name,” which is the display
Name for the Validated-SPN controlAccessRight object, with the ACE for the SPNvalidated write. dsacls is also case-sensitive, so be sure to specify the correct case for the
words in the displayName.
8.2. Creating a Computer for a Specific User or Group | 277
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
303
|
See Also
Recipe 8.1 for creating a computer account
8.3. Deleting a Computer
Problem
You want to delete a computer account.
Solution
Using a graphical user interface
1. Open the Active Directory Administrative Center.
2. In the right pane, type the name of the computer in the Global Search box, select
the desired domain in the scope, and then click the search icon.
3. In the search results, right-click the name of the computer and then click Delete.
4. In the Delete Confirmation dialog box, click Yes to complete the deletion of the
computer object.
Using a command-line interface
You can delete a computer using the built-in dsrm utility, as well as AdMod. For dsrm,
use the following syntax:
> dsrm "<Computer DN>"
For AdMod, enter the following:
> admod -b "<Computer DN>" -del
Using PowerShell
To delete an object using PowerShell, use the following syntax:
Remove-ADComputer -Identity "<Computer DN>" -Confirm:$False
8.4. Joining a Computer to a Domain
Problem
You want to join a computer to a domain after the computer object has already been
created in Active Directory.
278 | Chapter 8: Computer Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
304
|
Solution
Using a graphical user interface (steps specific to Windows 7, Windows 8, and
Windows Server 2012)
1. Log on to the computer that you want to join to the domain, and then open the
Control Panel.
2. Open the System applet.
3. In the “Computer name, domain, and workgroup settings section,” click “Change
settings.”
4. Click the Change button.
5. Under “Member of,” select Domain.
6. Enter the domain name that you want to join and click OK.
7. You may be prompted to enter credentials in order to join the computer to the
domain.
8. Reboot the computer.
Using a command-line interface
> netdom join <ComputerName> /Domain <DomainName> /UserD <DomainUserUPN>↵
/PasswordD * /UserO <ComputerAdminUser> /PasswordO * /Reboot
Using a command-line interface with PowerShell
Add-Computer -DomainName <DomainName> -Restart
Discussion
When trying to add a computer to Active Directory, either you can pre-create the
computer object as described in Recipes 8.1 and 8.2 before joining it to the domain, or
you can perform both operations at the same time.
Using a graphical user interface
If you have the correct permissions in Active Directory, you can actually create a com
puter object at the same time as you join it to a domain via the instructions described
in the GUI solution. Since the System applet doesn’t allow you to specify an OU for the
computer object, if it needs to create a computer object it will do so in the default
Computers container. See Recipe 8.16 for more information on the default Computers
container and how to change it.
8.4. Joining a Computer to a Domain | 279
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
305
|
Using a command-line interface
The netdom command will attempt to create a computer object for the computer during
a join if one does not already exist. An optional /OU switch can be added to specify the
OU in which to create the computer object.
You can unjoin a computer from a domain at the command line by using unjoin.exe,
another free download from the joeware website. unjoin.exe will not remove the com‐
puter account from the Active Directory domain; it will merely change the domain
membership locally on the machine itself.
See Also
Add-Computer cmdlet reference
8.5. Moving a Computer Within the Same Domain
Problem
You want to move a computer object to a different container or OU within the same
domain.
Solution
Using a graphical user interface
1. Open the ADUC snap-in (dsa.msc).
2. If you need to change domains, right-click on Active Directory Users and Com‐
puters in the left pane, select Connect to Domain, enter the domain name, and click
OK.
3. In the left pane, right-click on the domain and select Find.
4. Beside Find, select Computers.
5. Type the name of the computer and click Find Now.
6. In the Search Results window, right-click on the computer and select Move.
7. Browse to and select the new parent container or OU.
8. Click OK.
You can also use drag-and-drop functionality to move computers and
other objects.
280 | Chapter 8: Computer Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
306
|
Using a command-line interface
You can move a computer object to a new container using the built-in DSMove utility
or AdMod. To use DSMove, enter the following syntax:
> dsmove "<ComputerDN>" -newparent "<NewParentDN>"
To move a computer object using AdMod, use the following:
> admod -b "<ComputerDN>" -move "<NewParentDN>"
Using PowerShell
To move an Active Directory computer account using PowerShell, use the following
syntax:
Move-ADObject -Identity "<ComputerDN>" -TargetPath "<NewParentDN>"
Discussion
You can move computer objects around a domain without much impact on the com‐
puter itself. You just need to be cautious of the security settings on the new parent OU,
which may impact a user’s ability to manage the computer object in Active Directory.
Also, if GPOs are used differently on the new parent, it could impact booting and logon
times, and how the computer’s operating system behaves after a user has logged on.
See Also
Recipe 4.20 for moving an object to a different OU; Recipe 8.6 for moving a computer
to a different domain
8.6. Moving a Computer to a New Domain
Problem
You want to move a computer object to a different domain.
Solution
Using a graphical user interface (ADMT 3.2)
To migrate a computer object between domains, use the following steps:
1. Open the ADMT MMC snap-in (migrator.msc).
2. Right-click on the Active Directory Migration Tool folder and select the Computer
Migration Wizard.
3. On the Welcome screen, click Next.
8.6. Moving a Computer to a New Domain | 281
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
307
|
4. On the Domain Selection page, enter the DNS or NetBIOS name of the source and
target domains. Click Next.
5. On the Computer Selection Option screen, select the option to select the computer
from the domain and then click Next.
6. On the Computer Selection screen, click Add and use the object picker to select a
computer object. Click OK to return to the Computer Selection screen and then
click Next.
7. On the Organizational Unit Selection screen, enter the destination OU in the new
domain and then click Next.
8. On the Translate Objects screen, specify which objects should have new ACLs ap‐
plied in the new domain. Select any, none, or all of the following, and then click
Next to continue:
• Files and folders
• Local groups
• Printers
• Registry
• Shares
• User profiles
• User rights
9. On the Computer Options screen, click Next to maintain the default reboot time
of 5 minutes.
10. On the Object Property Exclusion screen, select any object properties that you do
not want to migrate and then click Next.
11. On the Conflict Management screen, click Next to accept the default, which will
not migrate the computer if there is a conflict.
12. On the Completing the Computer Migration Wizard screen, review the migration
settings and then click Finish to complete the move.
Using a command-line interface
The following command migrates a computer object from the adatum.com domain to
the emea.adatum.com domain. It will place the migrated object in the Finance OU and
will wait two minutes before rebooting the target computer:
ADMT COMPUTER /IF /N "FIN101-A" "FIN101-A" /SD:"adatum.com"↵
/TD:"emea.adatum.com"
/TO:"Finance" /RDL:2
282 | Chapter 8: Computer Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
308
|
Discussion
You can move objects between domains assuming you follow a few guidelines:
• The user requesting the move must have permission to modify objects in the parent
container of both domains.
• You should explicitly specify the target DC (serverless binds usually do not work).
This is necessary because the Cross Domain Move LDAP control is being used
behind the scenes. (For more information on controls, see Recipe 4.4.)
• The move operation must be performed against the RID master for both domains.
This is done to ensure that two objects that are being moved simultaneously don’t
somehow get assigned the same RID.
See Also
Recipe 4.4 for more on LDAP controls; MSDN: IADsContainer::MoveHere; “Active
Directory Migration Tool (ADMT) Guide: Migrating and Restructuring Active Direc‐
tory Domains”
8.7. Renaming a Computer
Problem
You want to rename a computer.
Solution
Using a graphical user interface (steps specific to Windows 7, Windows 8, and
Windows Server 2012)
1. Log on to the computer either directly or with a remote console application, such
as Remote Desktop Connection.
2. Open the Control Panel and double-click on the System applet.
3. In the “Computer name, domain, and workgroup settings section,” click the Change
Settings button.
4. On the Computer Name tab, click Change.
5. Under Computer Name, type the new name of the computer and click OK until
you are out of the System applet.
6. Reboot the computer.
8.7. Renaming a Computer | 283
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
309
|
Using a command-line interface
You can rename a computer object by using the built-in netdom utility with the following
syntax:
> netdom renamecomputer <ComputerName> /NewName <NewComputerName>↵
/UserD<DomainUserUPN> /PasswordD * /UserO <ComputerAdminUser> /PasswordO *↵
/Reboot
Using PowerShell
You can rename a computer by using PowerShell. After running the following command
on the computer that will be renamed, reboot the computer to complete the process.
Rename-Computer <NewComputerName>
Discussion
Renaming a computer consists of two operations: renaming the computer object in
Active Directory and renaming the hostname on the machine itself. To do it in one step
—an option that each of the three solutions offers—you must have permission in Active
Directory to rename the account and administrator permissions on the target machine.
For the rename operation to be complete, you must reboot the computer.
In some cases, renaming a computer can adversely affect services run‐
ning on the computer. For example, you cannot rename a machine that
is a domain controller, Exchange Server, or a Windows Certificate Au‐
thority without taking additional (and often significant) steps and
precautions.
Using a graphical user interface
After you rename the computer, you will be prompted to reboot. You can cancel if
necessary, but you’ll need to reboot at some point to complete the rename operation.
Using a command-line interface
The renamecomputer option in netdom can run remotely and includes a /Reboot switch
that allows you to automatically reboot the computer after the rename is complete.
See Also
Recipe 4.23 for renaming objects; “Netdom renamecomputer”
284 | Chapter 8: Computer Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
310
|
8.8. Adding or Removing a Computer Account
from a Group
Problem
You want to add or remove a computer account from an Active Directory security group.
Solution
Using a graphical user interface
1. Open the ADUC snap-in (dsa.msc).
2. If you need to change domains, right-click on Active Directory Users and
Computers in the left pane, select Connect to Domain, enter the domain name, and
click OK.
3. In the left pane, browse to the parent container of the objects you want to modify.
4. In the right pane, highlight each object you want to modify, right-click, and select
Properties.
5. On the “Member of ” tab, click Add.
6. Click the group to which you want to add the computer, and then click Add. To add
the computer to more than one group, press Ctrl while selecting the groups you
want to add the computer to, and then click Add.
7. To remove a group, select the group object and click Remove.
8. Click OK to finish.
Using a command-line interface
To add a computer object to a group, use the following syntax:
> admod -b "<GroupDN>" member:+:"<ComputerDN>"
To remove an object, replace :+: with :-: in the previous syntax.
Using PowerShell
To add a computer account to a group using PowerShell, use the following syntax:
Add-ADGroupMember -Identity "<GroupDN>" -Members "<ComputerDN>"
8.8. Adding or Removing a Computer Account from a Group | 285
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
311
|
Discussion
In Active Directory, both user and computer objects are security principals that can be
assigned rights and permissions in a domain. As such, computer objects can be added
to or removed from group objects to make for simpler resource administration. You
can make this change through ADAC, ADUC, or ADSI Edit, or by manually editing the
member attribute of the appropriate group object.
See Also
MSDN: NT-Group-Members attribute [AD Schema]; MSDN: Member Attribute [AD
Schema]
8.9. Testing the Secure Channel for a Computer
Problem
You want to test the secure channel of a computer.
Solution
Using a command-line interface
> nltest /server:<ComputerName> /sc_query:<DomainName>
Using PowerShell
Test-ComputerSecureChannel -Server <ComputerName> -Verbose
Discussion
Every member computer in an Active Directory domain establishes a secure channel
with a domain controller. The computer’s password is stored locally in the form of an
LSA secret and in Active Directory. The NetLogon service uses this password to establish
the secure channel with a domain controller. If for some reason the LSA secret and
computer password become out of sync, the computer will no longer be able to au‐
thenticate in the domain. The nltest /sc_query command can query a computer to
verify its secure channel is working. Here is sample output from the command when
things are working:
Flags: 30 HAS_IP HAS_TIMESERV
Trusted DC Name \\dc1.adatum.com
Trusted DC Connection Status Status = 0 0x0 NERR_Success
The command completed successfully
286 | Chapter 8: Computer Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
312
|
If a secure channel is failing, you’ll need to reset the computer as described in
Recipe 8.10. Here is sample output when things are not working:
Flags: 0
Trusted DC Name
Trusted DC Connection Status Status = 1311 0x51f ERROR_NO_LOGON_SERVERS
The command completed successfully
Using PowerShell
If the –Verbose parameter is not specified, the command only returns True when the
secure channel is working properly. By specifying verbose output, the command returns
“The secure channel between ‘Client Computer’, ‘Domain Controller’, and ‘Domain
Name’ is alive and working correctly.”
See Also
Recipe 8.10 for resetting a computer
8.10. Resetting a Computer Account
Problem
You want to reset a computer because its secure channel is failing.
Solution
Using a graphical user interface
1. Open the ADUC snap-in (dsa.msc).
2. If you need to change domains, right-click on Active Directory Users and Com‐
puters in the left pane, select Connect to Domain, enter the domain name, and click
OK.
3. In the left pane, right-click on the domain and select Find.
4. Beside Find, select Computers.
5. Type the name of the computer and click Find Now.
6. In the Search Results window, right-click on the computer and select Reset Account.
7. Click Yes to confirm the reset.
8. Click OK.
9. Rejoin the computer to the domain.
8.10. Resetting a Computer Account | 287
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
313
|
Using a command-line interface
You can use the DSMod utility to reset a computer’s password. You will need to rejoin
the computer to the domain after doing this:
> dsmod computer "<ComputerDN>" -reset
Another option is to use the netdom command, which can reset the secure channel
between the computer and the domain controller without affecting the computer’s
password, so that you do not need to rejoin it to the domain:
> netdom reset <ComputerName> /Domain <DomainName> /UserO <UserUPN> /PasswordO *
You can also use the nltest command to reset a secure channel using the following
syntax:
> nltest /sc_reset:<DomainName>\<DCName>
Using PowerShell
To reset the local computer’s secure channel by using PowerShell, run the following
command:
Test-ComputerSecureChannel -Repair
Discussion
When you’ve identified that a computer’s secure channel has failed, you’ll need to reset
the computer object, which consists of setting the computer object password to the name
of the computer. This is the default initial password for new computers. Every 30 days,
Windows computers automatically change their passwords in the domain. After you’ve
set the password, you’ll need to rejoin the computer to the domain since it will no longer
be able to communicate with a domain controller due to unsynchronized passwords.
However, the netdom reset command and the Test-ComputerSecureChannel com‐
mand will try to reset the password both on the computer and in Active Directory, which
will not necessitate rejoining it to the domain if successful.
From a practical standpoint, you should first attempt to reset the secure channel between
the computer and the domain using the netdom, Test-ComputerSecureChannel, or
nltest syntax, since doing so will not require you to unjoin and rejoin the computer
to the domain; in particular, this will save you from performing the associated reboots
involved with rejoining the domain. If resetting the secure channel does not correct the
issue you’re facing, you can then resort to resetting the computer’s password.
A new utility from joe Richards, named MachinePwd, is another way to change com‐
puter passwords from the command line. See joeware for more detail.
288 | Chapter 8: Computer Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
314
|
See Also
Recipe 8.4 for joining a computer to a domain
8.11. Finding Inactive or Unused Computers
Problem
You want to find inactive computer accounts in a domain.
Solution
These solutions might apply only to Windows-based machines. Other
types of machines—for example, Unix, Mac, and Network Attached
Storage (NAS)—that have accounts in Active Directory might not up‐
date their login timestamps or passwords, which are used to determine
inactivity.
Using a command-line interface
The following query will locate all inactive computers in the current forest:
> dsquery computer forestroot -inactive <NumWeeks>
You can also use domainroot in combination with the -d option to query a specific
domain:
> dsquery computer domainroot -d <DomainName> -inactive <NumWeeks>
Or you can target your query at a specific container:
> dsquery computer ou=MyComputers,dc=adatum,dc=com -inactive <NumWeeks>
You can also use the OldCmp joeware utility to create a report of all computer accounts
whose passwords are older than a certain number of days (90 by default) by using the
following syntax:
> oldcmp -report
To specify an alternate password age with oldcmp, use the –age x switch.
You can also use the –llts switch to use the lastLogonTimeStamp at‐
tribute to perform the age calculations. (Without this switch, oldcmp
will use pwdLastSet by default, which will work against any version of
Active Directory in any domain mode.)
8.11. Finding Inactive or Unused Computers | 289
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
315
|
Using PowerShell
You can also locate computers that have not been logged on to for a certain amount of
time using PowerShell, as shown in the following example that finds computers that
have not been logged on to in 60 days:
$DaysSince = (Get-Date).AddDays(-60)
Get-ADComputer -Filter * -Properties LastLogonDate |↵
Where-Object {($_.LastLogonDate -le $DaysSince) -and ($_.Enabled -eq $True)↵
-and ($_.LastLogonDate -ne $NULL)} | Select Name,LastLogonDate
Discussion
Using a command-line interface
The dsquery computer command is very handy for finding inactive computers that
have not logged in to the domain for a number of weeks or months. You can pipe the
results of the query to the dsrm command-line utility if you want to remove the inactive
computer objects from Active Directory in a single command.
You can also use OldCmp to disable inactive accounts, and then either delete them or
move them to an alternate OU. OldCmp has a number of safeties built into the utility
to prevent you from deleting a large number of computer accounts without meaning
to. For example, OldCmp will not delete an account unless it has first been disabled, it
will not modify more than 10 objects at a time unless you manually specify a higher
limit, and it simply will not do anything at all to a domain controller computer account
under any circumstances. Unless you have a requirement for quickly removing unused
computer objects, we’d recommend allowing them to remain inactive for at least three
months before removing them. If you don’t really care when the objects get removed,
use a year (i.e., 52 weeks) to be on the safe side.
See Also
Recipe 6.28 for finding users whose passwords are about to expire; “Find Inactive Users
using Powershell” (can be used with the -computersonly switch)
8.12. Changing the Maximum Number of Computers a
User Can Join to the Domain
Problem
You want to grant users the ability to join more or fewer than 10 computers to a domain.
This limit is called the machine account quota.
290 | Chapter 8: Computer Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
316
|
Solution
Using a graphical user interface
1. Open the ADSI Edit MMC snap-in (adsiedit.msc) and connect to the Domain
Naming Context.
2. Right-click on the domainDNS object for the domain you want to change and select
Properties.
3. Edit the ms-DS-MachineAccountQuota attribute and enter the new quota value.
4. Click OK twice.
Using a command-line interface
In the following LDIF code, replace <DomainDN> with the distinguished name of the
domain you want to change, and replace <Quota> with the new machine account quota:
dn: <DomainDN>
changetype: modify
replace: ms-DS-MachineAccountQuota
ms-DS-MachineAccountQuota: <Quota>
-
If the LDIF file was named change_computer_quota.ldf, you would then run the fol‐
lowing command:
> ldifde -v -i -f change_computer_quota.ldf
You can also make this change using AdMod, as follows:
> admod -b <DomainDN> ms-DS-MachineAccountQuota::<Quota>
Using PowerShell
You can modify the MachineAccountQuota attribute using PowerShell, as follows:
Set-ADDomain -Identity <DomainName>↵
-Replace @{"ms-DS-MachineAccountQuota"="<NewQuota>"}
Discussion
In a default Active Directory installation, members of the Authenticated Users group
can add and join up to 10 computer accounts in the default Computers container. The
number of computer accounts that can be created is defined in the attribute ms-DSMachineAccountQuota on the domainDNS object for a domain. The default setting is 10,
but you can easily change that to whatever number you want, including 0, via the meth‐
ods described in this recipe. If you set it to 0, users have to be granted explicit permissions
8.12. Changing the Maximum Number of Computers a User Can Join to the Domain | 291
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
317
|
in Active Directory to join computers; refer to Recipe 8.4 for instructions on granting
these permissions.
Another method for granting users the right to add computer objects, although not
recommended, is via Group Policy. If you grant the “Add workstation to domain” right
via Computer Configuration→Windows Settings→Security Settings→Local
Policies→User Rights Assignment on a GPO that’s been linked to the Domain Control‐
lers OU, then users will be able to create computer accounts even if they do not have
create child permissions on the default Computers container. This is a holdover from
Windows NT to maintain backward compatibility and should not be used unless ab‐
solutely necessary. In fact, a good security best practice would be to remove this user
right from any user or group objects that do not require it.
See Also
Recipe 8.4 for permissions needed to join computers to a domain; MS KB 251335 (Do‐
main Users Cannot Join Workstation or Server to a Domain); “Default limit to number
of workstations a user can join to the domain”
8.13. Modifying the Attributes of a computer Object
Problem
You want to modify one or more attributes of a computer object.
Solution
Using a graphical user interface
1. Open the Active Directory Administrative Center.
2. In the right pane, enter the name of the computer in the Global Search box, select
the desired domain in the scope, and then click the search icon.
3. In the search results, double-click the name of the computer to open the computer
properties.
4. Scroll down to the Extension section and then click the Attribute Editor tab.
5. Click the attribute that you want to modify and then click the Edit button.
6. Modify or set the desired value for the attribute and then click OK.
7. Click OK to finalize the attribute change.
292 | Chapter 8: Computer Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
318
|
Using a command-line interface
Create an LDIF file called modify_object.ldf with the following contents:
dn: <ComputerDN>
changetype: modify
add: <AttributeName><AttributeName>: <AttributeValue>
-
Then run the following command:
> ldifde -v -i -f modify_object.ldf
To modify an object using AdMod, you’ll use the following general syntax:
> admod -b <ComputerDN> <attribute>:<operation>:<value>
For example, you can add a location to a computer object using the following syntax:
> admod -b cn="Fin101,cn=Computers,dc=adatum,dc=com" location::"Berlin, Germany"
Using PowerShell
The Set-ADComputer cmdlet allows you to set commonly used attributes by using the
following syntax:
Set-ADComputer -Identity <ComputerDN> -<ObjectAttribute> "<Value>"
To set attributes that are not supported by the Set-ADComputer cmdlet natively, use the
following syntax:
Set-ADComputer -Identity <ComputerDN> -Replace @{<ObjectAttribute>="<Value>"}
Discussion
Like all objects within Active Directory, computer objects have various attributes that
can be queried, modified, and deleted during the day-to-day management of your do‐
main. Because computer objects inherit from the user class, they include similar infor‐
mational attributes to the user objects, as well as attributes that are specific to comput
er objects, including:
• Location
• Description
• operatingSystemVersion
• operatingSystemServicePack
• sAMAccountName
• pwdLastSet
• primaryGroupID
8.13. Modifying the Attributes of a computer Object | 293
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
319
|
Using PowerShell
See the full help file for the Set-ADComputer cmdlet to view the options and detailed
usage of the Add, Replace, Clear, and Remove parameters.
See Also
Recipe 8.11 for finding inactive or unused computers; Recipe 8.14 for finding computers
with a particular OS; MSDN: Computer System Hardware Classes [WMI]
8.14. Finding Computers with a Particular OS
Problem
You want to find computers that have a certain OS version, release, or service pack in a
domain.
Solution
Using a graphical user interface
You can perform this search using the Active Directory Users and Computers MMC
snap-in, as follows:
1. Open the ADUC MMC snap-in (dsa.msc).
2. Right-click on the domain, OU, or container that you wish to search and click Find.
3. In the Find drop-down box, select Computers.
4. Click on the Advanced tab. Click on Field and select Operating System.
5. Select the Condition that you want to search on from one of the following:
• Starts with
• Ends with
• Is (exactly)
• Is not
• Present
• Not present
6. In the Value field, enter the value that you want to search for, such as “Windows
Server 2012 Datacenter.”
7. Click Find Now.
294 | Chapter 8: Computer Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
320
|
Using a command-line interface
You can query for computer objects of a particular operating system using either
DSQuery or AdFind. To perform the query with DSQuery, use the following syntax:
> dsquery * <DomainDN> -scope subtree -attr "*" -filter "(&(↵
objectcategory=computer)(operatingSystem=Windows Server 2012 Datacenter))"
To use AdFind, enter the following:
> adfind -b <DomainDN> -f "(&(objectcategory=computer)↵
(operatingSystem=Windows Server 2012 Datacenter))"
Using PowerShell
To search for computers based on operating system version using PowerShell, use the
get-ADComputer cmdlet. The following example finds all computers that are running
Windows Server 2012 Datacenter without regard for the service pack level:
Get-ADComputer -Filter {OperatingSystem -eq "Windows Server 2012 Datacenter"} |↵
Select Name
The following example searches for all computers that are running Windows Server
2008 R2 Enterprise with Service Pack 1:
Get-ADComputer -Filter {OperatingSystem -eq "Windows Server 2008 R2 Enterprise"↵
-and OperatingSystemVersion -eq "6.1 (7601)"} | Select Name
Discussion
When a computer joins an Active Directory domain, the operating system attributes
are updated for the computer object. There are three of these attributes, which can be
used in queries to find computers that match certain OS-specific criteria, such as service
pack level.
These attributes include the following:
operatingSystem
Descriptive name of the installed operating system—for example, Windows Server
2008, Windows Server 2008 R2, and Windows Server 2012. The values of this at‐
tribute sometimes include special characters such as the copyright symbol, which
makes this attribute a poor choice for searching. However, if you know the de‐
scriptive name, it can still be a logical choice in a filter.
operatingSystemVersion
Numerical representation of the operating system—for example, 6.1 (7601) and 6.2
(9200). The version corresponds to the current service pack level, if one is installed.
For instance, 6.1 (7600) represents Windows Server 2008 R2 without a service pack,
while 6.1 (7601) represents Windows Server 2008 R2 with Service Pack 1. Windows
Server 2012 is represented by 6.2 (9200).
8.14. Finding Computers with a Particular OS | 295
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
321
|
operatingSystemServicePack
Current service pack level if one is installed—for example, Service Pack 2 and Ser‐
vice Pack 3.
This recipe typically applies only to Windows-based machines. Other
types of machines (e.g., Unix) that have accounts in Active Directory
might not automatically update their OS attributes, though some newer
Unix or Linux-based NAS devices have been configured to do so.
See Also
“Operating System Version (Windows)”
8.15. Binding to the Default Container for Computers
Problem
You want to bind to the default container that new computer objects are created in.
Solution
Using a graphical user interface
1. Open LDP.
2. From the menu, select Connection→Connect.
3. For Server, enter the name of a domain controller (or leave it blank to do a serverless
bind).
4. For Port, enter 389.
5. Click OK.
6. From the menu, select Connection→Bind.
7. Enter the credentials of a domain user or accept the default setting and bind as the
currently logged on user.
8. Click OK.
9. From the menu, select View→Tree.
10. For the DN, enter:
<WKGUID=aa312825768811d1aded00c04fd8d5cd,<DomainDN>>
where <DomainDN> is the distinguished name of a domain.
296 | Chapter 8: Computer Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
322
|
11. Click OK.
12. In the lefthand menu, you can now browse the default Computers container for the
domain.
Using a command-line interface
By default, all computer objects created in an Active Directory domain are placed into
the built-in Computers container. This default container has a significant limitation, in
that you are unable to link Group Policy Objects (GPOs) to the built-in container. If
you have one or more GPOs that you wish to apply to all computer objects in your
domain, you should modify the default location for computer accounts in AD. You can
use the redircmp utility to change this default location, as we will discuss in Recipe 8.16.
Using PowerShell
$strDomain = "<DomainDNSName>"
Set-Variable ADS_GUID_COMPUTERS_CONTAINER aa312825768811d1aded00c04fd8d5cd
$rootDSE = [ADSI]("LDAP://" + $strDomain + "/RootDSE")
$container = [ADSI]("LDAP://<WKGUID=" + $ADS_GUID_COMPUTERS_CONTAINER + "," +
$rootDSE.defaultNamingContext + ">")
$container.distinguishedName
Discussion
In much the same way that the TCP/IP protocol defines a list of well-known ports that
are commonly used by industry applications (TCP ports 20 and 21 for FTP, TCP port
80 for HTTP, and so on), Active Directory defines Well-Known GUIDs that map to
container objects that are present in every AD installation. The Domain NC defines
the following WKGUIDs:
• Users
• Computers
• System
• Domain Controllers
• Infrastructure
• Deleted Objects
• Lost and Found
The Configuration NC also defines its own Deleted Objects WKGUID.
8.15. Binding to the Default Container for Computers | 297
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
323
|
For example, the default Computers container has the following WKGUID:
aa312825768811d1aded00c04fd8d5cd
You can use the GUID to bind to the default Computers container in the domain using
the following ADsPath:
LDAP://<WKGUID=aa312825768811d1aded00c04fd8d5cd,dc=apac,dc=adatum,dc=com>
The list of well-known objects for a domain is contained in the wellKnownObjects
attribute of the domainDNS object for the domain. The wellKnownObjects attribute is
multivalued with DNWithBinary syntax. The following is an example of what that at‐
tribute looks like for the adatum.com domain:
B:32:AA312825768811D1ADED00C04FD8D5CD:cn=Computers,dc=adatum,dc=com;
B:32:F4BE92A4C777485E878E9421D53087DB:cn=Microsoft,cn=Program
Data,dc=adatum,dc=com;
B:32:09460C08AE1E4A4EA0F64AEE7DAA1E5A:cn=Program Data,dc=adatum,dc=com;
B:32:22B70C67D56E4EFB91E9300FCA3DC1AA:
cn=ForeignSecurityPrincipals,dc=adatum,dc=com;
B:32:18E2EA80684F11D2B9AA00C04F79F805:cn=Deleted Objects,dc=adatum,dc=com;
B:32:2FBAC1870ADE11D297C400C04FD8D5CD:cn=Infrastructure,dc=adatum,dc=com;
B:32:AB8153B7768811D1ADED00C04FD8D5CD:cn=LostAndFound,dc=adatum,dc=com;
B:32:AB1D30F3768811D1ADED00C04FD8D5CD:cn=System,dc=adatum,dc=com;
B:32:A361B2FFFFD211D1AA4B00C04FD7D83A:ou=Domain Controllers,dc=adatum,dc=com;
B:32:A9D1CA15768811D1ADED00C04FD8D5CD:cn=Users,dc=adatum,dc=com;
Each value has the format of:
B:NumberofBytes:GUID:DistinguishedName
As you can see, the GUID for the first value is the same as the one we used in the ADsPath
earlier to bind to the default Computers container.
See Also
Recipe 8.16 for changing the default Computers container; MSDN: Binding to WellKnown Objects Using WKGUID
8.16. Changing the Default Container for Computers
Problem
You want to change the container that computers are created in by default.
Solution
Using a graphical user interface
1. Open LDP.
298 | Chapter 8: Computer Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
324
|
2. From the menu, select Connection→Connect.
3. For Server, enter the name of a domain controller (or leave it blank to do a serverless
bind).
4. For Port, enter 389.
5. Click OK.
6. From the menu, select Connection→Bind.
7. Enter the credentials of a domain user.
8. Click OK.
9. From the menu, select Browse→Modify.
10. For DN, enter the distinguished name of the domainDNS object of the domain you
want to modify.
11. For Attribute, enter wellKnownObjects.
12. For Values, enter the following:
B:32:AA312825768811D1ADED00C04FD8D5CD:cn=Computers,<DomainDN>
where <DomainDN> is the same as the DN you enter for the DN field.
13. Select Delete for the Operation and click the Enter button.
14. Go back to the Values field and enter the following:
B:32:AA312825768811D1ADED00C04FD8D5CD:<NewComputersParent>,<DomainDN>
where <NewComputersParent> is the new parent container for new computer ob‐
jects (e.g., ou=Adatum Computers).
15. Select Add for the Operation and click the Enter button.
16. Click the Run button.
The result of the operations will be displayed in the right pane of the main LDP window.
Using a command-line interface
> redircmp "<NewParentDN>"
Discussion
Many Active Directory administrators do not use the Computers container within the
Domain Naming context as their primary computer repository. One reason is that since
it is a container and not an OU, you cannot apply Group Policy Objects to it. If you have
another location where you store computer objects, you might want to consider chang‐
ing the default container used to bind to the Computers container by changing the wellknown objects attribute, as shown in this recipe. This can be beneficial if you want to
ensure computers cannot sneak into Active Directory without having the appropriate
8.16. Changing the Default Container for Computers | 299
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
325
|
group policies applied to them. While you can also apply GPOs at the site or the domain
level, forcing new computers into a particular organizational unit ensures that those
computers receive the Group Policy settings that you want them to receive through
GPOs linked at the OU level. However, this does not protect you from an administrator
(whether intentionally or accidentally) explicitly creating a computer object in the in‐
correct OU; this only protects you from applications or utilities that do not allow or do
not require you to specify an OU when creating the computer.
See Recipe 8.15 for more information on how well-known objects are
specified in Active Directory.
See Also
“Redirecting the users and computers containers in Active Directory domains” (KB
324949)
8.17. Listing All the Computer Accounts in a Domain
Problem
You want to obtain a list of all computer accounts in an Active Directory domain.
Solution
Using a graphical user interface
1. Open the Active Directory Users and Computers MMC snap-in.
2. Right-click on the domain node and select Find.
3. In the Find drop-down box, select Computers and click Find Now.
All computer objects in the domain will be displayed in the Search Results window.
Using a command-line interface
> adfind -default -f objectCategory=computer
Using PowerShell
You can obtain a listing of computer accounts using PowerShell, as shown in the fol‐
lowing two examples:
Get-ADComputer -Filter * | Select Name
300 | Chapter 8: Computer Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
326
|
or
Get-ADObject -Filter {objectCategory -eq "Computer"} | Select Name
Discussion
Using PowerShell
The Get-ADComputer cmdlet simplifies the process of finding computers by removing
the need to know about the object class and object category. However, both methods
end up with the exact same results.
See Also
Get-ADComputer cmdlet reference; MSDN: Object Class and Object Category [Active
Directory]; MSDN: Object-Class Attribute [AD-Schema]
8.18. Identifying a Computer Role
Problem
You want to identify the role that a particular computer serves in an Active Directory
domain.
Solution
Using a graphical user interface
1. Open the Active Directory Users and Computers MMC snap-in (dsa.msc).
2. Right-click on the domain node and select Find.
3. In the Find drop-down box, select Computers and click Find Now.
The role of each computer will be displayed in the Machine Role column in the
Search Results window.
Using a command-line interface
> wmic computersystem get domainrole
For a domain controller that holds the PDC Emulator FSMO role, this will return the
following output:
DomainRole
5
8.18. Identifying a Computer Role | 301
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
327
|
For a DC that doesn’t hold the PDCe FSMO, this command will return
a value of 4.
Using PowerShell
Get-WmiObject Win32_ComputerSystem -ComputerName <ComputerFQDN>↵
-Property Name,DomainRole
Discussion
The DomainRole attribute returns a numeric value that identifies the role, as shown in
the following list:
• 0 is a standalone workstation.
• 1 is a member workstation.
• 2 is a standalone server.
• 3 is a member server.
• 4 is a backup domain controller.
• 5 is a primary domain controller.
Using a command-line interface
WMIC is the command-line component of the Windows Management Instrumentation
that uses aliases to enable you to easily access WMI namespaces from the command
line. To run wmic against a remote computer, specify the /node:"<ComputerFQDN>"
switch.
8.19. Protecting a Computer Against Accidental Deletion
Problem
You want to prevent a computer object from being accidentally deleted by an adminis‐
trator who selects the incorrect option in Active Directory Users and Computers.
Solution
Using a graphical user interface (steps specific to Windows Server 2008 and later)
1. Open Active Directory Users and Computers. Click on View and confirm that Ad‐
vanced Features is selected.
302 | Chapter 8: Computer Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
328
|
2. Drill down to the current domain. To connect to a different domain, right-click on
the top-level node and click “Change domain”; select the appropriate domain and
then drill down to it.
3. Right-click on the computer that you want to modify and click Properties.
4. Click on the Object tab.
5. Place a checkmark next to “Protect object from accidental deletion.”
6. Click OK.
Using a command-line interface (all versions)
dsacls <Computer DN> /d EVERYONE:SDDT
Using PowerShell (all versions)
Set-ADObject -Identity "<Computer DN>" -ProtectedFromAccidentalDeletion $True
Discussion
By default, all new OUs that are created in Windows Server 2008 and later will have this
protection enabled; however, no other object types are configured with this default
protection. If you attempt to delete a computer object that is protected using this option,
even when signed on as a Domain Admin or other similarly elevated account, you will
receive an “Access Denied” message until you manually remove the checkbox or man‐
ually remove the deny ACE associated with it.
Using the command-line or PowerShell method, you can apply this protection to group
objects in all versions of Windows Server, even though the GUI checkbox is available
only in Windows Server 2008 and later.
8.20. Viewing the RODCs That Have Cached a
Computer’s Password
Problem
You wish to view the RODCs that have cached a computer account’s password secrets.
Solution
Using a graphical user interface
1. Open the ADUC snap-in (dsa.msc).
8.20. Viewing the RODCs That Have Cached a Computer’s Password | 303
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
329
|
2. Click View→Advanced Features. In the left pane, right-click on the domain and
select Find.
3. In the Find drop-down box, select Computers. Select the appropriate domain.
4. Beside Name, type the name of the computer account and click Find Now.
5. In the Search Results window, double-click on the computer.
6. Select the Attribute Editor tab. Click Filter and ensure that there is a checkmark
next to Backlinks.
7. Scroll to the msDS-RevealedDSAs attribute to view a list of RODCs that have cached
this computer’s password secrets.
8. Click OK.
Using a command-line interface
> adfind -b <ComputerDN> msDS-RevealedDSAs
Using PowerShell
Get-ADComputer -Identity "<UserDN>" -Properties "msDS-RevealedDSAs" |↵
FL msDS-RevealedDSAs
Discussion
As discussed in Chapter 3, Windows Server 2008 introduced the Read-Only Domain
Controller (RODC) to improve the security of branch office and other remote envi‐
ronments. One of the security measures introduced by the RODC is the Password Rep‐
lication Policy (PRP), which specifies a list of users, computers, and groups that can and
cannot have their password secrets cached on one or more DCs. Each RODC maintains
a forward-link attribute called msDS-RevealedUsers, which lists the user and computer
accounts for whom each RODC has cached password secrets. Each computer account,
in turn, maintains a backlink called msDS-RevealedDSAs. This backlink can be queried
to determine which RODCs have stored password information for a particular user
account; however, like all backlinks, this attribute cannot be modified directly.
See Also
Recipe 3.2; Recipe 3.4
304 | Chapter 8: Computer Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
330
|
CHAPTER 9
Group Policy Objects
9.0. Introduction
Active Directory Group Policy Objects (GPOs) can customize virtually any aspect of a
computer or user’s desktop. They can also be used to install applications, secure a com‐
puter, run logon/logoff or startup/shutdown scripts, and much more. You can assign a
GPO to a local computer, site, domain, or organizational unit. This is called scope of
management (SOM), because only the users or computers that fall under the scope of
the computer, OU, site, or domain will process the GPO. Assigning a GPO to a SOM is
referred to as linking the GPO. You can restrict the application of GPOs further by using
security groups to filter which users or groups they will apply to or by using inheritance
blocking.
You can also use a WMI filter to restrict the application of a GPO. A WMI filter is simply
a WMI query that can search against any information on a client’s computer. If the WMI
filter returns a true value (i.e., the client computer matches the conditions that are
specified in the filter), the GPO will be processed; otherwise, it will not. So not only do
you have all of the SOM options for applying GPOs, but also you can use any WMI
information available on the client’s computer to determine whether GPOs should be
applied. For more on the capabilities of GPOs, we recommend reading Active Directo‐
ry, Fifth Edition, by Brian Desmond et al. (O’Reilly).
Group Policies are defined by a set of files that are replicated to each domain controller
in a domain and a groupPolicyContainer (GPC) object that is stored in the cn=Poli
cies,cn=System,<DomainDN> container. GPC objects contain information related to
software deployment, wireless deployments, IPSec assignments, and metadata about
the version of the GPO. GPC objects are used for linking to OUs, sites, and domains.
The guts of GPOs are stored on the filesystem of each domain controller in Group Policy
Template (GPT) files and can be found in the %SystemRoot%\SYSVOL\sysvol
\<DomainDNSName>\Policies directory.
305
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
331
|
So why are there two storage points for GPOs? The need for the Active Directory object
is obvious: to be able to link GPOs to other types of objects, the GPOs need to be
represented in Active Directory. Group Policy Templates are stored in the OS filesystem
to reduce the amount of data that needs to be replicated within Active Directory.
For legacy Windows computers, each Group Policy Object stores individual copies of
Administrative templates (.adm files) in the SYSVOL folder. In an environment con‐
taining numerous GPOs, this can add significantly to the amount of data that must be
replicated to the SYSVOL share on all domain controllers in a domain. However, since
Windows Vista, GPO settings are deployed using a new XML-based .admx format, and
administrators have the option to configure a single Central Store to provide a storage
instance for all GPOs in a domain.
Furthermore, Windows Server 2008 introduced Group Policy Preferences (GPPs), a
new group of GPO settings that can be used to manage configuration items that could
not be managed previously (or that could not be managed particularly well) via GPOs,
including managing the creation of file shortcuts, ODBC connections, drive mappings,
printer connections, and more.
Managing GPOs
While the new capabilities of GPOs were significant when first introduced with Active
Directory, the obvious things that were lacking were good tools for managing them.
The dual storage nature of GPOs creates a lot of problems. Initially, Microsoft did not
provide a scriptable interface for accessing and manipulating GPO settings. Addition‐
ally, there were no tools for copying or migrating GPOs from a test environment to
production. Back then the primary tool for managing GPOs was the Group Policy Editor
(GPE), now known as the Group Policy Management Editor (GPME). The main func‐
tion of the GPME is to modify GPO settings; it does not provide any other management
capabilities.
Microsoft realized these were major issues for Group Policy adoption, so it developed
the Group Policy Management Console (GPMC) with the release of Windows Server
2003. The GPMC is an MMC snap-in that provides the kitchen sink of GPO manage‐
ment capabilities: you can create, delete, import, copy, back up, restore, and model GPO
processing from a single interface. Perhaps what is even better is the scriptable API that
comes with the GPMC. Pretty much every function you can accomplish with the GPMC
tool, you can do via a script.
306 | Chapter 9: Group Policy Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
332
|
The only major feature that is still lacking is the ability to modify the
settings of a GPO directly via command line or script (although there
is some ability to modify specific types of settings, improvement is
needed). Previously, this could be done with only the GPOE, but there
are third-party options that can provide this type of functionality. The
GPMC still provides numerous options for migrating GPOs, which ad‐
dresses the majority of the problems people face today.
In versions prior to Windows Server 2008, GPMC is an out-of-band download that can
be obtained from Microsoft. In Windows Server 2008 and later, Group Policy Manage‐
ment is a feature, and it can be installed on Windows client computers as part of the
Remote Server Administration Tools (RSAT). Note that throughout the book we use
the name “Group Policy Management” instead of GPMC in order to match up with the
shortcut and menu names used by Windows.
Another tool that you can download from the Microsoft website is GPInventory. This
is an incredibly useful tool that will allow you to perform a software inventory for users
and computers in a domain or OU, and to track information about the rollout of GPOs
in AD, such as computers that have not applied new GPO information. Additionally,
the Group Policy Best Practice Analyzer (GP BPA) is a free download that can help you
identify Group Policy configuration errors within your environment.
The majority of solutions presented in this chapter use the Group Policy Management
snap-in. Most of the command-line solutions we provide will use one of the scripts
provided in the Group Policy Management Console Sample Scripts install available from
the Microsoft Download Center. A whole host of precanned scripts have been written
already, in a mix of VBScript and JScript, which serve as great command-line tools and
good examples to start scripting GPOs. These scripts are available by default in the C:
\Program Files (x86)\Microsoft Group Policy\GPMC Sample Scripts directory on a Win‐
dows Server 2012 server that has had the sample scripts installed on it. You can execute
them in one of two ways, either by using cscript:
> cscript listallgpos.wsf
or, if you make cscript your default WSH interpreter, by executing the file directly. To
make cscript your default interpreter, run this command:
> cscript //H:cscript
9.1. Finding the GPOs in a Domain
Problem
You want to find all of the GPOs that have been created in a domain.
9.1. Finding the GPOs in a Domain | 307
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
333
|
Solution
Using a graphical user interface
1. Open the Group Policy Management snap-in (gpmc.msc).
2. In the left pane, expand the Forest container.
3. Expand the Domains container.
4. Browse to the desired domain.
5. Expand the domain and then expand the Group Policy Objects container. All of
the GPOs in the domain will be listed under that container.
Using a command-line interface
You can generate a list of all GPOs in a domain using the listastallgpos.wsf script, as well
as DSQuery and AdFind:
> listallgpos.wsf [/domain:<DomainDNSName>] [/v]
> dsquery * domainroot -filter (objectcategory=grouppolicycontainer)
-attr displayname
> adfind -default -f (objectcategory=grouppolicycontainer)↵
displayname
Using PowerShell
To get all of the GPOs in the current domain and return their display name, run the
following PowerShell command:
Get-GPO -All | Select DisplayName
Discussion
See Recipe 9.0 for more on how GPOs are stored in Active Directory.
Using PowerShell
You can obtain the details from a single GPO by replacing -All with the -Name param‐
eter, followed by the friendly name of the GPO, such as Get-GPO -Name "Default
Domain Policy".
See Also
Get-GPO cmdlet reference; “Group Policy Cmdlets in Windows PowerShell”
308 | Chapter 9: Group Policy Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
334
|
9.2. Creating a GPO
Problem
You want to create a Group Policy Object within Active Directory.
Solution
Using a graphical user interface
1. Open the Group Policy Management snap-in (gpmc.msc).
2. In the left pane, expand the Forest container, expand the Domains container, and
browse to the domain that will contain the new GPO.
3. Expand the domain and then right-click on the Group Policy Objects container
and select New.
4. Enter the name of the GPO, ensure that the Source Start GPO is set to (none), and
then click OK.
Using a command-line interface
> creategpo.wsf <GPOName> [/domain:<DomainDNSName>]
Using PowerShell
To create a GPO called "Marketing GPO" in the current domain, use the following
syntax:
New-GPO -Name "Marketing GPO"
If the GPO is successfully created, the cmdlet will output the display name of the GPO,
along with the GUID and other information.
Discussion
When you create a GPO through the Group Policy Management snap-in, it is initially
empty with no settings or links configured. See Recipe 9.6 for more on modifying GPO
settings, and Recipe 9.14 for more on creating a link.
See Also
New-GPO cmdlet reference; “Group Policy Cmdlets in Windows PowerShell”
9.2. Creating a GPO | 309
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
335
|
9.3. Copying a GPO
Problem
You want to copy the properties and settings of one GPO into another GPO.
Solution
Using a graphical user interface
1. Open the Group Policy Management snap-in (gpmc.msc).
2. In the left pane, expand the Forest container, expand the Domains container, browse
to the domain of the source GPO, expand the domain, and then expand the Group
Policy Objects container.
3. Right-click on the source GPO and select Copy.
4. Right-click on the Group Policy Objects container and select Paste.
5. Select whether you want to use the default permissions or to preserve the existing
permissions from the GPO being copied, and click OK.
6. A status window will pop up that will indicate whether the copy was successful.
Click OK to close.
7. Rename the new GPO by right-clicking it in the left pane and selecting Rename.
Using a command-line interface
> copygpo.wsf <SourceGPOName> <TargetGPOName>
Using PowerShell
Copy-GPO -SourceName "<SourceGPOName>" -TargetName "<TargetGPOName>"
Discussion
Prior to the GPMC tool, two of the biggest problems with managing GPOs in large
environments were migrating GPOs from one forest to another and copying GPOs from
one domain to another within the same forest. It is common to have a test forest where
GPOs are initially created, configured, and tested before moving them into production.
The problem before GPMC was that once you had the GPO the way you wanted it in
the test forest, there was no easy or well-publicized way to move it to the production
forest.
With the GPMC and the Group Policy Management snap-in, you can simply copy GPOs
between domains. You can also import GPOs, which is similar to a copy operation. A
310 | Chapter 9: Group Policy Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
336
|
GPO import uses a backup of the source GPO in order to create the new GPO. See
Recipe 9.7 for more information on importing a GPO.
Some properties of GPOs, such as security group filters, UNC paths, and Restricted
Groups, may vary slightly from domain to domain; for example, a logon script that runs
from \\SERVERA\share in the source domain may need to run on \\SERVERB\share
in the target domain. In that case, you can use a GPMC migration table to help facilitate
the transfer of those types of references to the target domain. For more information on
migration tables, see the GPMC help file and Recipe 9.8.
Using PowerShell
PowerShell has greatly simplified the process of managing GPOs. With PowerShell, you
can copy all of the GPOs in one domain to a different domain in a single line of
PowerShell.
See Also
Recipe 9.7 for importing a GPO; Recipe 9.8; Copy-GPO cmdlet reference
9.4. Deleting a GPO
Problem
You want to delete a GPO.
Solution
Using a graphical user interface
1. Open the Group Policy Management snap-in (gpmc.msc).
2. In the left pane, expand the Forest container, expand the Domains container, browse
to the domain of the target GPO, expand the domain, and then expand the Group
Policy Objects container.
3. Right-click on the target GPO and select Delete.
4. Click OK to confirm.
Using a command-line interface
> deletegpo.wsf <GPOName> [/domain:<DomainDNSName>]
9.4. Deleting a GPO | 311
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
337
|
To retain the links to the deleted GPO, use the /keeplinks switch.
Otherwise, all links will be deleted along with the GPO.
Using PowerShell
Remove-GPO -Name "<GPO Friendly Name>" -KeepLinks
Discussion
When you delete a GPO through the Group Policy Management snap-in, it attempts to
find all links to the GPO in the domain and will delete them if the user has permissions
to delete the links. If the user does not have the necessary permissions to remove the
links, the GPO will still get deleted, but the links will remain intact. Any links external
to the domain the GPO is in are not automatically deleted. For this reason, it is a good
practice to view the links to the GPO before you delete it. Links to deleted GPOs show
up as “Not Found” in the Group Policy Management snap-in.
Using PowerShell
To delete a GPO in a remote domain, use the -DomainName switch, followed by the
FQDN of the domain.
See Also
Recipe 9.13 for viewing the links for a GPO; Remove-GPO cmdlet reference
9.5. Viewing the Settings of a GPO
Problem
You want to view the settings that have been defined in a GPO.
Solution
Using a graphical user interface
1. Open the Group Policy Management snap-in (gpmc.msc).
2. In the left pane, expand the Forest container, expand the Domains container, browse
to the domain of the target GPO, expand the domain, and then expand the Group
Policy Objects container.
3. Click on the target GPO.
4. In the right pane, click on the Settings tab.
312 | Chapter 9: Group Policy Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
338
|
5. Click the Show All link to display all configured settings.
Using a command-line interface
> getreportsforgpo.wsf "<GPOName>" <ReportLocation> [/domain:<DomainDNSName>]
Using PowerShell
Get-GPOReport -Name "<GPO Friendly Name>" -Path <Path With File Name>↵
-ReportType HTML
Discussion
The Group Policy Management snap-in can generate an XML or HTML report that
contains all of the settings in a GPO. See Recipe 9.6 for more information on how to
modify GPO settings.
Using PowerShell
The Get-GPOReport cmdlet can produce output in either HTML or XML format, by
using the –ReportType HTML or –ReportType XML switch, respectively.
See Also
Get-GPOReport cmdlet reference
9.6. Modifying the Settings of a GPO
Problem
You want to modify the settings associated with a GPO.
Solution
Using a graphical user interface
1. Open the Group Policy Management snap-in (gpmc.msc).
2. In the left pane, expand the Forest container, expand the Domains container, browse
to the domain of the target GPO, expand the domain, and then expand the Group
Policy Objects container.
3. Right-click on the target GPO and select Edit. This will bring up the Group Policy
Management Editor.
9.6. Modifying the Settings of a GPO | 313
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
339
|
4. Browse through the Computer Configuration or User Configuration settings and
modify them as necessary.
Using PowerShell
You can modify a registry-based setting in a GPO by using PowerShell. The following
example modifies the IE High Sec GPO by disabling the Flash add-in:
Set-GPRegistryValue -Name "IE High Sec"↵
-key "HKLM\Software\Policies\Microsoft\Internet Explorer"↵
-ValueName "DisableFlashInIE" -Type String -Value "1"
Discussion
Modifying GPOs has historically been performed from a GUI. Up until the SetGPRegistryValue cmdlet was introduced, there wasn’t an easy way to modify a GPO
from a command-line environment. Note that the Set-GPRegistryValue cmdlet is re‐
stricted to registry settings only and thus isn’t as fully featured as the Group Policy
Management Editor.
See Also
Recipe 9.3 for copying a GPO; Recipe 9.5 for viewing the settings of a GPO; Recipe 9.7
for importing settings into a GPO; Set-GPRegistryValue cmdlet reference
9.7. Importing Settings into a GPO
Problem
You want to import settings from one GPO to another.
Solution
Using a graphical user interface
1. Open the Group Policy Management snap-in (gpmc.msc).
2. In the left pane, expand the Forest container, expand the Domains container, ex‐
pand the domain of the target GPO, and expand the Group Policy Objects con‐
tainer.
3. Right-click on the target GPO and select Import Settings.
4. Click Next.
5. Click the Backup button if you want to take a backup of the GPO you are importing
into.
314 | Chapter 9: Group Policy Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
340
|
6. Click Next.
7. Select the backup folder location and click Next.
8. Select the backed-up GPO you want to import from and click Next.
9. The Import wizard then will scan to see whether there are any security principals
or UNC paths in the GPO being imported from. If there are, it will give you an
option to modify those settings.
10. Click Next.
11. Click Finish.
Using a command-line interface
> importgpo.wsf "<GPOBackupLocation>" "<OrigGPOName>" "<NewGPOName>"
Using PowerShell
Import-GPO -BackupGpoName "<Friendly Name of Source GPO>"↵
-TargetName "<Friendly Name of Target GPO>" -Path "<Path to backed up GPO>"
Discussion
The Group Policy Management import function uses a backup of the source GPO to
create the new “imported” GPO. This means you must first back up the source GPO.
You can then import the settings from that GPO into a new GPO, which may be in the
same domain or in a completely different forest. Importing a GPO is a great way to help
facilitate transferring GPO settings from a test environment to production.
Some properties of GPOs, such as security group filters and UNC paths, may vary
slightly from domain to domain; a logon script that runs from \\SERVERA\share in the
source domain may need to run on \\SERVERB\share in the target domain, for example.
In this case, you can use a migration table to help facilitate the transfer of those kinds
of references to the target domain. For more information on migration tables, see
Recipe 9.8.
Using PowerShell
Be aware that the target GPO will be overwritten by the contents of the GPO backup
during the import operation.
See Also
Recipe 9.3 for copying a GPO; Recipe 9.8; Recipe 9.23 for backing up a GPO; ImportGPO cmdlet reference
9.7. Importing Settings into a GPO | 315
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
341
|
9.8. Creating a Migration Table
Problem
You want to create a migration table to assist in copying or migrating a GPO from one
domain or forest to another.
Solution
Using a graphical user interface
1. Open the Group Policy Management snap-in (gpmc.msc). Navigate to the forest
and domain containing the GPOs you wish to migrate or copy.
2. Right-click on the Group Policy Objects node and select Open Migration Table
Editor.
3. You will begin with a blank migration table. To populate the source fields from
existing data, click on Tools→Populate from GPO or Tools→Populate from Backup.
Select the GPO or the backup that you wish to import. Optionally, place a checkmark
next to “During scan, include security principals from the DACL on the GPO.” Click
OK.
4. Modify the Destination Name column of any entries to match their format in the
destination forest or domain.
5. To add a new entry, enter the name of the item in the Source Name column. In the
Source Type column, select one of the following:
• User
• Computer
• Domain Local Group
• Domain Global Group
• Universal Group
• UNC Path
• Free Text or SID
6. To delete an entry, right-click on the entry and select Delete.
7. To configure an entry to use the same information as configured in the source GPO,
right-click on the entry and select Set Destination→Same As Source.
8. To configure an entry to use the relative name of the destination, right-click on the
entry and select Set Destination→Map by Relative Name. For example, if you have
an entry for the salesuser@adatum.com user in a GPO that you wish to copy to the
316 | Chapter 9: Group Policy Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
342
|
mycompany.com forest, selecting Map by Relative Name will populate the entry in
the destination GPO as salesuser@mycompany.com.
9. To ensure that you have properly formatted all entries in the table, click Tools→Val‐
idate Table, then click File→Save or File→Save As to save the migration table.
Using a command-line interface
> createmigrationtable.wsf <DestinationFileName> /GPO:<GPO> /MapByName
Discussion
One of the convenient features of the Group Policy Management snap-in is the ability
to copy a GPO’s settings from one GPO to another, or to migrate GPOs between domains
or forests. In some cases, certain entries in the GPO may need to be modified to suit the
needs of the destination domain or forest. For example, a UNC for user home directories
will likely need to be modified to correspond to a server or DFS share in the destination,
as well as individual user or group names. To address this need, you can create and
populate a migration table to automatically transform the necessary entries on one or
more GPOs.
Using a command-line interface
To create a migration table from the command line, use the createmigrationtable.wsf
script that is included in the ~\GPMC Sample Scripts folder. The script requires two
arguments: the destination filename and the GPO that it should be populated from.
As an alternative to the /GPO: switch, you can use /BackupLocation: to populate the
migration table from a GPO backup. By default, a migration table that you create using
this script will use Same As Source mapping, or you can specify the /MapByName pa‐
rameter to use relative name mapping.
See Also
Recipe 9.3 for more on copying a GPO; Recipe 9.7 for information on importing settings
into a GPO
9.9. Creating Custom Group Policy Settings
Problem
You want to deploy settings via Group Policy that are not covered by the default set of
GPO templates that come with Active Directory.
9.9. Creating Custom Group Policy Settings | 317
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
343
|
Solution
Windows comes preloaded with a number of default templates that define a number of
settings that can be controlled via GPO. To control and deploy settings for additional
or third-party applications, you’ll need to create your own custom ADM or ADMX file
to manage the settings you require. You’ll create this file in Notepad or another simple
text editor, and save it as <FileName>.adm or <FileName>.admx. For example, the
following ADMX file will add a new search provider to Internet Explorer using a cus‐
tomized ADMX file:
<?xml version="1.0" encoding="utf-8"?> <policyDefinitions
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" revision="1.0"
schemaVersion="1.0"
xmlns="http://www.microsoft.com/GroupPolicy/PolicyDefinitions">
<policyNamespaces>
<target prefix="search" namespace="Microsoft.Policies.search" />
<using prefix="inetres" namespace="Microsoft.Policies.InternetExplorer" />
</policyNamespaces>
<resources minRequiredRevision="1.0" />
<policies>
<policy name="PopulateSearchProviderList_1" class="User"
displayName="$(string.PopulateSearchProviderList)"
explainText="$(string.IE_Explain_PopulateSearchProviderList)"
key="Software\Policies\Microsoft\Internet Explorer\SearchScopes">
<parentCategory ref="inetres:InternetExplorer" />
<supportedOn ref="inetres:SUPPORTED_IE7Vista"/>
<enabledList>
<item key="Software\Policies\Microsoft\Internet Explorer\SearchScopes"
valueName="Version">
<value>
<decimal value="VERSION" />
</value>
</item>
<item key="Software\Policies\Microsoft\Internet
Explorer\SearchScopes\SUBKEY1" valueName="DisplayName">
<value>
<string>NAME1</string>
</value>
</item>
<item key=" Software\Policies\Microsoft\Internet
Explorer\SearchScopes\SUBKEY1" valueName="URL">
<value>
<string>URL1</string>
</value>
</item>
</enabledList>
</policy>
<policy name="PopulateSearchProviderList_2" class="Machine"
displayName="$(string.PopulateSearchProviderList)"
explainText="$(string.IE_Explain_PopulateSearchProviderList)"
318 | Chapter 9: Group Policy Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
344
|
key="Software\Policies\Microsoft\Internet Explorer\SearchScopes">
<parentCategory ref="inetres:InternetExplorer" />
<enabledList> Insert same as user policy above </enabledList>
</policy>
</policies>
</policyDefinitions>
In addition to the ADMX file, you will need to create an ADML file using a format
similar to the following:
<?xml version="1.0" encoding="utf-8"?>
<policyDefinitionResources xmlns:xsd=http://www.w3.org/2001/XMLSchema
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" revision="1.0"
schemaVersion="1.0"
xmlns="http://www.microsoft.com/GroupPolicy/PolicyDefinitions">
<displayName>enter display name here</displayName>
<description>enter description here</description>
<resources>
<stringTable>
<string id="PopulateSearchProviderList">Populate List of search
providers</string>
<string id="IE_Explain_PopulateSearchProviderList">
This policy setting will allow you to populate a list of search providers that
will be displayed in Internet Explorer's search box. If you enable this policy
setting and if the "Restrict search providers to a specific list of search
providers" Group Policy setting is enabled, this list will be the only list
that appears in the Internet Explorer drop-down list. If the "Add a specific
list of search providers to the user's search provider list" Group Policy
setting is enabled, this list will be added to the user's list of search
providers. If you disable this policy setting or do not configure it,
users will have complete freedom to create their own search provider list.
</string>
</stringTable>
</resources>
</policyDefinitionResources>
Discussion
When you create a custom ADMX file, save it to the %windir%\policydefinitions folder;
the ADML file will be saved in the %windir%\policydefinitions\<Definition Lan
guage> folder. After saving the files, you can edit a GPO to use the new settings. The
templates will automatically populate in the Administrative Templates section of the
GPO.
See Also
“Managing Group Policy ADMX Files Step-by-Step Guide”
9.9. Creating Custom Group Policy Settings | 319
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
345
|
9.10. Assigning Logon/Logoff and Startup/Shutdown
Scripts in a GPO
Problem
You want to assign either user logon/logoff scripts or computer startup/shutdown
scripts in a GPO.
Solution
Using a graphical user interface (steps specific to Windows Server 2008 and later)
1. Open the Group Policy Management snap-in (gpmc.msc).
2. In the left pane, expand the Forest container, expand the Domains container, ex‐
pand the domain of the target GPO, and expand the Group Policy Objects con‐
tainer.
3. Right-click on the target GPO and select Edit. This will bring up the Group Policy
Management Editor.
4. Browse to Computer Configuration→Policies→Windows Settings→Scripts. If you
want to assign a user logon or logoff script, browse to User Configuration→Poli‐
cies→Windows Settings→Scripts.
5. In the right pane, double-click on the type of script you want to add.
6. Click the Add button.
7. Select the script by typing its name or browsing to its location.
8. Optionally, type any script parameters in the Script Parameters field.
9. Click OK twice.
Discussion
When you assign a script in a GPO, you can reference a script that either is stored locally
on the domain controller somewhere under the SYSVOL share or is stored in a UNC
path to a remote fileserver. The default storage location is in the <DomainName>\SYS
VOL\<DomainName>\scripts folder—for example, \\adatum.com\sysvol\adatum.com
\scripts.
320 | Chapter 9: Group Policy Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
346
|
9.11. Installing Applications with a GPO
Problem
You want to install an application on a group of computers using a GPO.
Solution
Using a graphical user interface
1. Open the Group Policy Management snap-in (gpmc.msc).
2. In the left pane, expand the Forest container, expand the Domains container, ex‐
pand the domain of the target GPO, and expand the Group Policy Objects
container.
3. Right-click on the target GPO and select Edit. This will bring up the Group Policy
Management Editor.
4. Expand Software Settings under Computer Configuration or User Configuration,
depending on which you want to target the installation for.
5. Right-click on Software Installation and select New→Package.
6. Browse to the network share that has the MSI package for the application and click
OK. Be sure to specify a UNC path such as \\servername\share\installer.msi. If you
enter a local file path on the DC, such as c:\packages\pro.msi, the client will not be
able to access the installer.
7. Select whether you want to assign the application or publish it, and click OK. You
can also click Advanced to define further how you want to deploy the software
installation package.
Discussion
Installing applications with a GPO is a powerful feature, but you must be careful about
the impact it can have on your network throughput and clients. If the MSI package you
are installing is large in size, it will take a while for it to download to the client computer.
This can result in sluggish performance on the client, especially over a heavily utilized
connection. (Software installation does not occur over slow links, by default.) You’ll also
want to make sure you’ve thoroughly tested the application before deployment. After
you’ve configured the GPO to install an application, it will be only a short period of time
before it has been installed on all targeted clients. If there is a bug in the application or
the installer program is faulty, the impact could be severe to your user base and support
staff alike.
9.11. Installing Applications with a GPO | 321
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
347
|
Your two options for deploying an application are to assign it or to publish it. If you
assign an application using the “deploy at logon” option, it will be installed automatically
on the targeted clients when users log on to those machines. If you publish an application
or assign it without choosing this option, it will be installed the first time a user doubleclicks on a shortcut to the application or attempts to open a file that requires the appli‐
cation. A published application also can be installed manually from the Programs and
Features applet in the Control Panel on the target computers. You can assign an appli‐
cation to both user and computer objects, but you can publish applications only to
users.
If you need to exert more granular control over your software installa‐
tions than is enabled by Group Policy, you should investigate leveraging
the additional capabilities of dedicated deployment software such as
Microsoft’s System Center Configuration Manager (ConfigMgr).
9.12. Disabling the User or Computer Settings in a GPO
Problem
You want to disable either the user or the computer settings of a GPO.
Solution
Using a graphical user interface
1. Open the Group Policy Management snap-in (gpmc.msc).
2. In the left pane, expand the Forest container, expand the Domains container, ex‐
pand the domain of the target GPO, and expand the Group Policy Objects con‐
tainer.
3. Right-click on the target GPO and select GPO Status.
4. You can select User Configuration Settings Disabled to disable the user settings,
Computer Configuration Settings Disabled to disable the computer settings, or All
Settings Disabled to disable both user and computer settings.
Using PowerShell
$gpm = New-Object -ComObject GPMgmt.GPM
$gpmConstants = $gpm.GetConstants()
$objDomain = $gpm.GetDomain("<Domain FQDN>", "", $gpmConstants.UseAnyDC)
$objGpo = $objDomain.GetGPO("{<GPO GUID>}")
322 | Chapter 9: Group Policy Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
348
|
$objGpo.SetComputerEnabled($true)
$objGpo.SetUserEnabled($false)
Discussion
GPOs consist of two parts, a user section and a computer section. The user section
contains settings that are specific to a user that logs in to a computer, while the computer
section defines settings that apply to the computer regardless of which user logs in. You
can enable or disable either the user configuration or the computer configuration sec‐
tion of a GPO, or both. By disabling both, you effectively disable the GPO. This can be
useful if you want to stop a GPO from applying settings to clients, but you do not want
to delete it, remove the links, or clear the settings.
Disabling the user configuration or the computer configuration is useful in environ‐
ments that have separate OUs for computers and users. Typically, you would disable the
computer configuration for GPOs linked to the users’ OU, and vice versa. Disabling half
of the GPO in this way makes GPO processing a tiny bit more efficient but likely will
have almost no impact on overall performance.
Using PowerShell
Although 26 cmdlets are dedicated to managing Group Policy, none of them can be
used to enable or disable computer or user settings. Instead, we utilize a COM object
in PowerShell.
See Also
“Group Policy Cmdlets in Windows PowerShell”; MSDN: GPMGPO.SetUserEnabled;
MSDN: GPMGPO.SetComputerEnabled
9.13. Listing the Links for a GPO
Problem
You want to list all of the links for a particular GPO.
Solution
Using a graphical user interface
1. Open the Group Policy Management snap-in (gpmc.msc).
2. In the left pane, expand the Forest container, expand the Domains container, ex‐
pand the domain of the target GPO, and expand the Group Policy Objects
container.
9.13. Listing the Links for a GPO | 323
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
349
|
3. Click on the GPO you want to view the links for.
In the right pane, the defined links for the GPO will be listed under the Scope tab.
Using a command-line interface
> dumpgpoinfo.wsf "<GPOName>"
Using PowerShell
Get-ADOrganizationalUnit -Filter * -Properties * |↵
Where {$_.gPLink -match "<GPO GUID>"} | Select Name
Discussion
See Recipe 9.0 for more information on GPO linking.
Using PowerShell
The built-in PowerShell cmdlets are not useful for retrieving links. Instead, we rely on
searching the other direction: the OUs themselves. In the PowerShell solution, we get
all of the OUs in the current domain and then filter them for any that have the specified
GPO GUID stored in the gpLink attribute. This indicates that the GPO is linked to the
OU. Finally, we select only the name of the OUs.
See Also
Recipe 9.0; Recipe 9.14 for creating a GPO link to an OU
9.14. Creating a GPO Link to an OU
Problem
You want to apply the GPO settings to the users and/or computers in an OU. This is
called linking a GPO to an OU.
Solution
Using a graphical user interface
1. Open the Group Policy Management snap-in (gpmc.msc).
2. In the left pane, expand the Forest container, expand the Domains container, and
expand the target domain.
3. Right-click on the OU you want to link and select Link an Existing GPO.
324 | Chapter 9: Group Policy Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
350
|
4. Select from the list of available GPOs and click OK.
Using PowerShell
New-GPLink -Name "<GPO Display Name>" -Target "<Container DN>"
Discussion
Linking a GPO is the process whereby you assign a scope of management (SOM), which
can be an OU, site, or domain. The solutions show how to link a GPO to an OU, but
they easily could be modified to link to a site or domain.
See Recipe 5.14 for details on how to link an OU by modifying the gpLink attribute,
instead of using the Group Policy Management interface.
Using PowerShell
During the creation of the new link, you can also specify the link order by using the –
Order <Number> parameter.
See Also
New-GPLink cmdlet reference; MSDN: GPM-SOM.CreateGPOLink
9.15. Blocking Inheritance of GPOs on an OU
Problem
You want to block inheritance of GPOs on an OU.
Solution
Using a graphical user interface
1. Open the Group Policy Management snap-in (gpmc.msc).
2. In the left pane, expand the Forest container, expand the Domains container, and
expand the target domain.
3. Right-click on the OU you want to block inheritance for and select Block
Inheritance.
9.15. Blocking Inheritance of GPOs on an OU | 325
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
351
|
Using PowerShell
Below are two ways to block inheritance by using PowerShell. The first example uses
one of the cmdlets from the Group Policy module, whereas the other relies on a COM
object.
Set-GPInheritance -Target "<OU DN>" -IsBlocked Yes
$gpm = New-Object -ComObject GPMgmt.GPM
$gpmConstants = $gpm.GetConstants()
$objDomain = $gpm.GetDomain("<Domain FQDN>", "", $gpmConstants.UseAnyDC)
$objOU = $objDomain.GetSOM("<OU DN>")
$objOU.GPOInheritanceBlocked = $true
Discussion
By default, GPOs are inherited down through the directory tree. If you link a GPO to a
top-level OU, that GPO will apply to any objects within the child OUs. Sometimes that
may not be what you want, and you can disable inheritance as described in the solutions.
Try to avoid blocking inheritance when possible because it can make determining what
settings should be applied to a user or computer difficult. If someone sees that a GPO
is applied at a top-level OU, he may think it applies to any object under it. Using the
Resultant Set of Policies (RSoP) snap-in can help identify what settings are applied to a
user or computer (see Recipe 9.25).
See Also
Recipe 9.25; Set-GPInheritance cmdlet reference; MSDN: GPMSOM; MSDN:
GPOInheritanceBlocked; MSDN: GPMDomain.GetSOM
9.16. Enforcing the Settings of a GPO Link
Problem
You want to ensure that a GPO’s settings are enforced regardless of any Block Inheritance
settings that have been enforced farther down the scope of management.
Solution
Using a graphical user interface
1. Open the Group Policy Management snap-in (gpmc.msc).
2. In the left pane, expand the Forest container, expand the Domains container, ex‐
pand the domain of the target GPO, and expand the container containing the link
you want to enforce.
326 | Chapter 9: Group Policy Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
352
|
3. Right-click on the link you want to configure and place a checkmark next to En‐
forced. To remove the Enforced setting, right-click on the link and remove the
checkmark.
Using PowerShell
Set-GPLink -Guid "<GPOGUID>" -Target "<SiteName>" -Enforced Yes
Discussion
As a counterpoint to the ability to block inheritance of a GPO for a particular site,
domain, or OU, an administrator can configure a particular GPO link as Enforced,
meaning that the settings contained in that GPO will be configured for that SOM re‐
gardless of the presence of any Block Inheritance configuration. This is useful in a de‐
centralized environment, for example, where a central IT department has configured a
certain Group Policy baseline that it wishes to enforce regardless of what individual
departments may have configured on their own. Just like security filtering and Block
Inheritance, though, we recommend that you use this function sparingly, as it can create
complex troubleshooting issues when trying to determine where and how the Group
Policy application is failing.
Remember that the Enforced setting is configured against a particular
link to a GPO, not against the GPO itself. This means that one GPO can
be linked to several locations, but not all of those links need to be
enforced.
See Also
Recipe 9.15; Set-GPLink cmdlet reference; MSDN:IGPMSearchCriteria; MSDN:
GPMC Object Model
9.17. Applying a Security Filter to a GPO
Problem
You want to configure a GPO so that it applies only to members of a particular security
group.
9.17. Applying a Security Filter to a GPO | 327
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
353
|
Solution
Using a graphical user interface
1. Open the Group Policy Management snap-in (gpmc.msc).
2. In the left pane, expand the Forest container, expand the Domains container, ex‐
pand the target domain, and expand the Group Policy Objects container.
3. Click on the GPO you want to modify.
4. In the right pane under Security Filtering, click the Add button.
5. Use the Object Picker to select a group and click OK.
6. Highlight Authenticated Users and click the Remove button.
7. Click OK to confirm.
Using a command-line interface
> setgpopermissions.wsf "<GPOName>" "<GroupName>" /permission:Apply
> setgpopermissions.wsf "<GPOName>" "Authenticated Users" /permission:None
Using PowerShell
Set-GPPermission -Name <GPO Display Name> -TargetName "<Group Name>"↵
-TargetType Group -PermissionLevel GpoApply"
Discussion
You can use security filtering to restrict the users, groups, or computers that a GPO
applies to by granting or denying the Apply Group Policy permission on the ACL of the
GPO. By default, Authenticated Users are granted the Apply Group Policy right on all
new GPOs, so you will also need to remove this right if you want to restrict the GPO to
be applied only to members of one specific group.
As a rule, you should avoid using Deny permissions as part of any custom security filter,
because this can lead to confusion with accounts that are members of groups with con‐
flicting filter settings. For example, if a user is a member of a group that has Deny set
in the filter and is also a member of a group that is allowed to apply the policy, the Deny
setting will always win. This can be difficult to troubleshoot, particularly if nested group
memberships are involved.
328 | Chapter 9: Group Policy Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
354
|
Be very careful when changing permissions on GPOs. If you create a
very restricted GPO and apply a security filter to it, also be sure to put
tight controls on who can modify the GPO and how. If for some reason
that security filter were removed (resulting in no security filters), the
restrictive GPO could be applied to every user or computer in the
domain.
Using PowerShell
The Set-GPPermission cmdlet allows you to apply one of the following preconfigured
permissions:
• GpoRead
• GpoApply
• GpoEdit
• GpoEditDeleteModifySecurity
• None
See Also
Set-GPPermission cmdlet reference;MSDN: GPM.CreatePermission; MSDN:
GPMGPO.GetSecurityInfo
9.18. Delegating Administration of GPOs
Problem
You want to delegate permissions on GPOs and related tasks within Active Directory.
Solution
Using a graphical user interface
To delegate the ability to create GPOs, do the following:
1. Open the Group Policy Management snap-in (gpmc.msc).
2. Navigate to the Group Policy Objects node and click on the Delegation tab.
3. To add permissions for a new user or group to create GPOs, click Add. Use the
object picker to select the object you want and click OK.
To delegate permissions on a particular GPO, follow these steps:
9.18. Delegating Administration of GPOs | 329
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
355
|
1. Open the Group Policy Management snap-in (gpmc.msc).
2. Navigate to the GPO that you want to delegate permissions for and click on the
Delegation tab.
3. To add permissions for a new user or group, click Add. Use the object picker to
select the object you want and click OK.
4. In the Permissions drop-down box, select “Read”, “Edit settings,” or “Edit settings,
delete, and modify security,” then click OK.
To delegate Group Policy−related tasks on a particular site, domain, or OU, do the
following:
1. Open the Group Policy Management snap-in (gpmc.msc).
2. Navigate to the site, domain, or OU that you want to delegate permissions for and
click on the Delegation tab.
3. In the Permission drop down, select “Link GPOs,” “Perform Group Policy Modeling
analyses,” or “Read Group Policy Results data.”
4. To add permissions for a new user or group, click Add. Use the object picker to
select the object you want and click OK.
5. In the Permissions drop-down box, select “This container only” or “This container
and all child containers”; then click OK.
Discussion
In addition to using Active Directory users and groups to control how GPOs are applied
within a site, domain, or OU, you can also use ACLs to delegate permissions over GPOs
to allow you to decentralize the administration of them in your organization.
You can delegate the ability to do the following:
• Create GPOs
• Manage the settings of an individual GPO
• Link GPOs to a site, domain, or OU
• Create WMI filters
• Manage an individual WMI filter
While the ability to delegate administration in this manner is quite simple to implement,
it’s critical that you fully understand the security implications that it carries. For example,
the ability to link GPOs to an entire site or domain should be granted only to highly
330 | Chapter 9: Group Policy Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
356
|
trusted administrators as it can have far-reaching implications for the performance and
behavior of your network.
See Also
MS KB 250842 (Troubleshooting Group Policy Application Problems); Recipe 9.17 for
more on using security filtering to control GPO behavior
9.19. Importing a Security Template
Problem
You want to import a security template into a GPO.
Solution
Using a graphical user interface
1. Open the Group Policy Management snap-in (gpmc.msc).
2. In the left pane, expand the Forest container, expand the Domains container, ex‐
pand the domain of the GPO you want to target, and expand the Group Policy
Objects container.
3. Right-click on the target GPO and select Edit.
4. Navigate to Computer Configuration→Policies→Windows Settings.
5. Right-click on Security Settings and select Import Policy.
6. Browse to the template you want to import and click Open.
Discussion
Rather than manually configuring the plethora of security settings available in Win‐
dows, you can use a template. Windows 2003 shipped with several templates, including
templates for high-security workstations and high-security domain controllers. How‐
ever, Windows 2008 and later have scaled back the number of default templates and
now only include three templates: a default base template, a default domain controller
template, and a default member server template. Each template is useful in a scenario
where you need to reset security settings back to the default state.
9.19. Importing a Security Template | 331
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
357
|
9.20. Creating a WMI Filter
Problem
You want to create a WMI filter.
Solution
Using a graphical user interface
1. Open the Group Policy Management snap-in (gpmc.msc).
2. In the left pane, expand the Forest container, expand the Domains container, ex‐
pand the target domain, and click the WMI Filters container.
3. Right-click on the WMI Filters container and select New.
4. Enter a name and description for the filter.
5. Click the Add button.
6. Select the appropriate namespace, enter a WQL query, and click OK.
7. Repeat steps 5 and 6 for as many queries as you need to add.
8. Click the Save button.
Discussion
WMI filters provide another way to filter how GPOs are applied to clients. WMI filters
live in Active Directory as objects under the WMIPolicy container within the System
container for a domain. A WMI filter consists of a WMI Query Language (WQL) query
that, when linked to a GPO, will be run against all clients that the GPO applies to. If the
WQL returns a true value (i.e., it returns nonempty results from the WQL query), the
GPO will continue to process. If the WQL query returns false (nothing is returned
from the query), the GPO will not be processed.
The great thing about WMI filters is that the vast amount of information that is available
in WMI on a client becomes available to filter GPOs. You can query against CPU, mem‐
ory, disk space, hotfixes installed, service packs installed, applications installed, running
processes—the list goes on and on.
For example, creating a GPO that applies only to computers that are running a specific
version of Windows would have been really difficult to accomplish without a WMI filter.
Either you would have had to create a security group that contained all of those com‐
puters as members (and apply a security filter) or you would have had to move all of
those workstations to a particular OU. With a WMI filter, this becomes trivial to create.
Bear in mind, however, that there is client performance overhead associated with WMI
332 | Chapter 9: Group Policy Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
358
|
queries, as each computer will need to process the WMI query to determine whether a
particular GPO should or should not be applied. Here is a sample WQL query that would
return true when run on a Windows Server 2012 Datacenter server:
select * from Win32_OperatingSystem↵
where Caption = "Microsoft Windows Server 2012 Datacenter"
The introduction of Group Policy Preferences created significant new options in terms
of how GPOs can be targeted and filtered. Prior to the introduction of Group Policy
Preferences, you were limited to filtering using only WMI filters to control whether the
entire GPO is applied. With WMI filters, you cannot specify individual settings within
a GPO. Group Policy Preferences, on the other hand, support item-level targeting, where
individual settings can be targeted based on criteria such as IP address, whether that
machine is a laptop or desktop, security group membership, and so on.
See Also
Recipe 9.21 for applying a WMI filter to a GPO; MSDN: Querying with WQL
9.21. Applying a WMI Filter to a GPO
Problem
You want to apply a WMI filter to a GPO.
Solution
Using a graphical user interface
1. Open the Group Policy Management snap-in (gpmc.msc).
2. In the left pane, expand the Forest container, expand the Domains container, ex‐
pand the domain of the GPO you want to target, and expand the Group Policy
Objects container.
3. Click on the target GPO.
4. At the bottom of the right pane, on the Scope tab, select a WMI filter from the list
of WMI filters.
5. After you’ve selected the WMI filter, click Yes to change the filter.
Discussion
You can link only one WMI filter to a GPO at any time. This is not an overly restrictive
limitation, though, because you still can link more than one GPO to a site, domain, or
9.21. Applying a WMI Filter to a GPO | 333
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
359
|
OU. If you need multiple WMI filters to apply to a GPO, copy the GPO and apply a
different WMI filter to it. See Recipe 9.20 for more information on WMI filters.
Keep in mind that requiring your clients to process multiple WMI filters
will have an impact on their performance at logon time and during the
GPO background refresh process.
9.22. Configuring Loopback Processing for a GPO
Problem
You want to configure a GPO to use loopback processing that will enforce consistent
computer settings regardless of which user logs on to a computer.
Solution
Using a graphical user interface
1. Open the Group Policy Management snap-in (gpmc.msc).
2. Navigate to the GPO that you want to configure. Right-click on the GPO and select
Edit Settings.
3. Navigate to Computer Configuration→Policies→Administrative→Templates Sys‐
tem→Group Policy. Double-click on “Configure user Group Policy loopback pro‐
cessing mode”. Select the radio button next to Enabled.
4. In the Mode drop-down box, select either Merge or Replace. (See this recipe’s
“Discussion” for more information on these two options.)
5. Click OK.
Discussion
GPOs are applied to user/computer combinations on an Active Directory network based
on the site, domain, and OU that the user and computer objects belong to. If the user
and computer are located in two separate locations, the user will receive the GPOs that
apply to the user’s container combined with those that apply to the computer’s container.
However, there may be cases where you want a user to receive GPOs based solely on the
location of the computer objects. In this case, you will enable loopback processing in
one of two modes:
334 | Chapter 9: Group Policy Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
360
|
Merge mode
In this mode, any GPOs that are associated with the user will be applied first. The
GPOs associated with the computer object will be applied after the GPOs associated
with the user object, thereby giving them a higher precedence than the user GPOs.
In this case, the user will still receive any GPO settings associated with her user
object, but settings configured for the computer will override in the case of any
conflicts.
Replace mode
In this mode, only the list of GPOs that apply to the computer object will be applied.
See Also
MS KB 231287 (Loopback Processing of Group Policy)
9.23. Backing Up a GPO
Problem
You want to back up a GPO.
Solution
Using a graphical user interface
1. Open the Group Policy Management snap-in (gpmc.msc).
2. In the left pane, expand the Forest container, expand the Domains container, ex‐
pand the domain of the GPO you want to back up, and expand the Group Policy
Objects container.
3. Right-click on the GPO you want to back up and select Back Up.
4. For Location, enter the folder path to store the backup files.
5. For Description, enter a descriptive name for the backup.
6. Click the Back Up button.
7. You will see a progress bar and status message that indicates whether the backup
was successful.
8. Click OK to exit.
Using a command-line interface
> backupgpo.wsf "<GPOName>" "<BackupFolder>" /comment:"<BackupComment>"
9.23. Backing Up a GPO | 335
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
361
|
Using PowerShell
Backup-Gpo -Name <GPO Display Name> -Path <Path to Backup Folder>↵
-Comment "<Backup Description>"
Discussion
The Group Policy Management snap-in and the Backup-Gpo cmdlet both provide a way
to back up individual (or all) GPOs. A GPO backup consists of a set of folders and files
that catalog the GPO settings, filters, and links, and is created in the backup location
you specify. You can back up a GPO to a local drive or over the network to a fileserver.
Restoring a GPO is just as easy and is described in Recipe 9.24.
In legacy versions of Windows, the only way to back up GPOs was by backing up the
System State on a domain controller. The System State includes Active Directory and
the SYSVOL share (both components are needed to completely back up a GPO). To
restore a GPO using this method, you’d have to boot into DS Restore mode and perform
an authoritative restore of the GPO(s) you were interested in. Needless to say, the meth‐
ods are significantly easier now.
A good practice is to back up your GPO backups. Since all the backup information is
captured in a series of files, you can back up that information to media, which provides
two levels of restore capability. You could restore the last backup taken, which could be
stored on a domain controller or fileserver, or you could go to tape and restore a previous
version.
In the folder you specify to store the GPO backups is a list of folders that have GUIDs
for names. This does not make it very easy to distinguish which backups are for which
GPOs. A quick way to find that out is to use the querybackuplocation.wsf script. This
will list each folder GUID name and the corresponding GPO it is for:
> querybackuplocation.wsf "c:\gpmc backups"
Using PowerShell
The -Path switch allows you to back up GPOs to either a local file location such as C:
\GPOBackups or a remote UNC path such as \\SERVER1\GPOBackups.
See Also
Recipe 9.24 for restoring a GPO; Backup-GPO cmdlet reference; and MSDN:
GPMGPO.Backup
336 | Chapter 9: Group Policy Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
362
|
9.24. Restoring a GPO
Problem
You want to restore a GPO.
Solution
Using a graphical user interface
1. Open the Group Policy Management snap-in (gpmc.msc).
2. In the left pane, expand the Forest container, expand the Domains container, ex‐
pand the domain of the GPO you want to restore, and expand the Group Policy
Objects container.
3. Right-click on the GPO you want to restore and select Restore from Backup.
4. Click Next.
5. Select the backup folder location and click Next.
6. Select the backup you want to restore and click Next.
7. Click Finish.
8. You will see the restore status window. After it completes, click OK to close the
window.
Using a command-line interface
> restoregpo.wsf "<BackupFolder>" "<GPOName>"
Using PowerShell
Restore-GPO -Name "<GPO Display Name>" -Path <Backup Location>
Discussion
To restore a GPO using the Group Policy Management snap-in, you first need a valid
backup of the GPO. The procedure for backing up a GPO is described in Recipe 9.23.
You can then restore the GPO, even if the GPO has been deleted. To restore a deleted
GPO, use the following steps:
1. Right-click on the Group Policy Objects container in the target domain and select
Manage Backups.
2. Highlight the GPO you want to restore and click the Restore button.
3. Click Yes to confirm.
9.24. Restoring a GPO | 337
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
363
|
4. Click OK after the restore completes.
If you don’t have a valid backup of the GPO, but you do have another GPO that is
identical or similar to the one you want to restore (perhaps in another forest), you can
copy that GPO to replace the one you want to restore.
Keep in mind that restoring a GPO does not restore the links that were associated with
that GPO, since the gpLink attribute is configured on the container that the GPO was
linked to and not the container itself. See Recipe 9.3 for more on copying GPOs.
See Also
Recipe 9.3 for copying a GPO; Recipe 9.23 for backing up a GPO; Restore-GPO cmdlet
reference; MSDN: GPMDomain.RestoreGPO
9.25. Simulating the RSoP
Problem
You want to simulate the Resultant Set of Policies (RSoP) based on OU, site, and security
group membership. This is also referred to as Group Policy Modeling.
Solution
Using a graphical user interface
1. Open the Group Policy Management snap-in (gpmc.msc).
2. In the left pane, right-click Group Policy Modeling and select Group Policy Mod‐
eling Wizard.
3. Click Next.
4. Select a domain controller to process the query and click Next.
5. Under User Information and/or Computer Information, either select the container
you want to simulate to contain the user or computer, or select a specific user or
computer account, and click Next.
6. Select a site if necessary, and specify whether you wish to simulate a slow network
connection or loopback processing, and then click Next.
7. If you selected a target user container or user account in step 5, you will be presented
with an option to simulate different group membership. Click Next when you are
done.
338 | Chapter 9: Group Policy Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
364
|
8. If you selected a target computer container or computer account in step 5, you will
be presented with an option to simulate different group membership. Click Next
when you are done.
9. If you selected a target user container or user account in step 5, you will be presented
with an option to simulate any additional WMI filters. Click Next when you are
done.
10. If you selected a target computer container or computer account in step 5, you will
be presented with an option to simulate any additional WMI filters. Click Next
when you are done.
11. Click Next to start the simulation.
12. Click Finish.
13. In the right pane of the Group Policy Management snap-in window, the results of
the simulation will be displayed.
Discussion
You can simulate the RSoP based on user-defined OU, site, group, and domain mem‐
bership. This is very powerful because it allows you to create one or more GPOs, simulate
them being applied to a user and computer, and determine whether any changes are
necessary before deployment.
See Also
Recipe 9.26 for viewing the RSoP
9.26. Viewing the RSoP
Problem
You want to view the actual RSoP for a user and computer. This is a great tool for
determining whether policies are being applied correctly on a client.
Solution
Using a command-line interface
To display summary RSoP data to the screen, use the following command:
> gpresult /R
To generate an RSoP in HTML format, use the following command:
> gpresult /H RSoP.htm
9.26. Viewing the RSoP | 339
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
365
|
You can specify a /S option and the name of a computer to target, which allows you to
run the command remotely. For a complete list of options with either version, run
gpresult /? from a command line.
Discussion
If you implement more than a few GPOs, it can get confusing as to what settings will
apply to users. To address this problem, you can query the resultant set of policies on a
client to determine which settings have been applied.
The registry on the target computer is another source of information. You can view the
list of policies that were applied to the computer by viewing the subkeys under this key:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Group Policy\History
The settings that were applied are not stored in the registry, but you can obtain the GPO
name, distinguished name, SYSVOL location, version, and where the GPO is linked.
Finally, you can also rely on the Windows Event Logs for troubleshooting. Since Win‐
dows Vista, the logs have been improved greatly and now include a Group Policy op‐
erational log. Additionally, the source name for events now uses “Group Policy,” which
makes it easier to track down Group Policy events.
See Also
Recipe 9.25 for simulating the RSoP
9.27. Refreshing GPO Settings on a Computer
Problem
You’ve made some changes to a GPO and want to apply them to a computer by refreshing
the group policies for the computer.
Solution
Using a command-line interface
On a Windows XP or later computer, use this command:
> gpupdate [/target:{Computer | User}]
Using PowerShell
Invoke-GPUpdate -Computer "<Machine FQDN>"
340 | Chapter 9: Group Policy Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
366
|
Discussion
By default, Group Policy settings will refresh automatically every five minutes on a
domain controller and every 90 minutes (with an additional random offset between
zero and 30 minutes) on clients and member servers. To force GPO settings to refresh
sooner than that, you will need to run the gpupdate utility on the client computer. With
gpupdate, you can force all settings to be applied with the /force option (the default is
only changed settings). You can apply the computer or user settings of GPOs using
the /target option, and you can force a logoff or reboot after the settings have been
applied using the /logoff or /boot option. Windows Server 2012 introduced a remote
Group Policy update feature built into the Group Policy Management snap-in. (Rightclick on an OU and you can force a Group Policy update on all computers in the OU.)
Using PowerShell
The Invoke-GPUpdate cmdlet includes a number of optional switches that map to the
gpupdate.exe command-line option, including -Computer, -User, -Force, -Logoff,
-Boot, and -Sync.
See Also
Invoke-GPUpdate cmdlet reference
9.28. Restoring a Default GPO
Problem
You’ve made changes to the Default Domain Security Policy, Default Domain Controller
Security Policy, or both, and now you want to reset them to their original configuration.
Solution
Using a command-line interface
The following command will replace both the Default Domain Security Policy and the
Default Domain Controller Security Policy on a domain controller. You can specify
Domain or DC instead of Both, to only restore one or the other:
> dcgpofix /target:Both
Note that this must be run from a domain controller in the target domain where you
want to reset the GPO.
9.28. Restoring a Default GPO | 341
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
367
|
Discussion
If you’ve made changes to the default GPOs in the Windows Server 2003 or later version
of Active Directory and would like to revert back to the original settings, the dcgpofix
utility is your solution. dcgpofix works with a particular version of the schema. If the
version it expects to be current is different from what is in Active Directory, it will not
restore the GPOs. You can work around this by using the /ignoreschema switch, which
will restore the GPO according to the version dcgpofix thinks is current. The only time
you might experience this issue is if you install a service pack on a domain controller
(DC1) that extends the schema but the changes have not yet replicated to a second
domain controller (DC2). If you try to run dcgpofix from DC2, you will receive the error
since a new version of the schema and the dcgpofix utility were installed on DC1. Note
that this tool isn’t a panacea. It doesn’t always return permissions to the exact state after
the domain controller promotion process. Because of this, backups of Group Policy
should be relied on first.
9.29. Creating a Fine-Grained Password Policy
Problem
You want to create a Fine-Grained Password Policy (FGPP).
Solution
Using a graphical user interface (steps specific to Windows 7, Windows 8,
and Windows Server 2012)
1. Open Active Directory Administrative Center.
2. At the top of the left pane, click the tree view icon.
3. Browse to the desired domain and then expand the domain, expand System, and
then highlight the Password Settings container.
4. Right-click the Password Settings container in the left pane, click New, and then
click Password Settings.
5. Type in a name for the settings, enter a precedence value, and then fill in the desired
password settings. Note that settings with a red asterisk are mandatory.
6. In the Directly Applies To section near the bottom, click the Add button to specify
users or groups to apply the password settings to.
7. When finished, click OK to save the settings and apply the settings to the specified
users or groups.
342 | Chapter 9: Group Policy Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
368
|
Using PowerShell
Fine-Grained Password Policy objects can also be created in PowerShell, as follows:
New-ADFineGrainedPasswordPolicy -Name "HighSec2" -Precedence 1↵
-ComplexityEnabled $true -Description "High Security Password Policy"↵
-DisplayName "Domain Users PSO" -PasswordHistoryCount "12" -MinPasswordLength↵
"15" -MinPasswordAge "1" -MaxPasswordAge "180" -LockoutDuration "30"↵
-LockoutObservationWindow "1" -LockoutThreshold "999"
Discussion
Prior to Windows Server 2008, only one password and account lockout policy func‐
tioned per domain (note that we are only talking about domain user accounts); this has
been updated since Windows Server 2008 once you reach the Windows Server 2008
domain functional level. Fine-Grained Password Policies are controlled by creating one
or more msDS-PasswordSettingsObjects, or PSOs for short, in the cn=Password Set
tings Container,cn=System,cn=<Domain DN> container. Each PSO can apply to one
or more user or group objects, and each is assigned a precedence that will allow Active
Directory to determine which PSO to enforce if more than one can apply to a particular
user.
See Also
Recipe 9.31; Recipe 9.30; New-ADFineGrainedPasswordPolicy cmdlet reference
9.30. Editing a Fine-Grained Password Policy
Problem
You want to modify a Fine-Grained Password Policy.
Solution
Using a graphical user interface
1. Open Active Directory Administrative Center.
2. At the top of the left pane, click the tree view icon.
3. Browse to the desired domain, expand the domain, expand System, and then high‐
light the Password Settings container.
4. In the right pane, right-click on the desired policy and then click Properties.
5. Update the desired settings and click OK to save the new settings.
9.30. Editing a Fine-Grained Password Policy | 343
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
369
|
Using a command-line interface
The following command renames a PasswordSettingsObject:
psomgr -rename newname -pso oldname -forreal
The following modifies a PSO’s maximum password age to 60 days:
psomgr -mod -pso TestPSO -pwdlen 60 -forreal
The following adds the Marketing group to the list of groups that a PSO will apply to:
psomgr -applyto cn=Marketing,cn=Users,dc=ADATUM,dc=COM -pso TestPSO -forreal
The following removes the Marketing group from the list of groups that a PSO will
apply to:
psomgr -unapplyto cn=Marketing,cn=Users,dc=ADATUM,dc=COM -pso TestPSO -forreal
You can also use the Domain\sAMAccountName syntax instead of a dis‐
tinguished name.
Using PowerShell
The following modifies a PSO’s maximum password length:
Set-ADFineGrainedPasswordPolicy -Identity "<PSO Name>" -MinPasswordLength 20
To rename a PSO, use the following syntax:
Set-ADFineGrainedPasswordPolicy -Identity "<PSO Name>" -DisplayName "HighSec2"
Discussion
Once a PasswordSettingsObject has been created, you can modify the password and
account lockout settings controlled by the object, as well as the users and groups that
the PSO should apply to. Since the PasswordSettingsObject is an Active Directory
object class, these modifications can be made using any interface that can modify objects.
When working from the command line, the psomgr tool allows you to modify one or
multiple PSOs at a time, and can also create “starter” PSOs using the psomgr -
quickstart -forreal syntax. The -quickstart switch creates a PSO that replicates
the domain-linked password policy, as well as the following two PSOs:
cn=pwd_policy_admin
Creates a PSO with a minimum password length of 15, with passwords that expire
every 35 days and that are subject to a 30-minute lockout after 25 bad-password
attempts
344 | Chapter 9: Group Policy Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
370
|
cn=pwd_policy_serviceid
Creates a PSO with a minimum length of 15, with passwords that expire every 364
days and that are not subject to account lockout
The full syntax for psomgr.exe can be obtained by typing psomgr.exe /? at a command
prompt, or by visiting the joeware website.
See Also
Recipe 9.31; Recipe 9.29; Recipe 6.17
9.31. Viewing the Effective PSO for a User
Problem
You want to determine which PSO is in effect for a particular user.
Solution
Using a graphical user interface
1. Open Active Directory Users and Computers. Click on View and confirm that there
is a checkmark next to Advanced Features.
2. Browse to the user or group in question; right-click on the object and click
Properties.
3. Click on the Attribute Editor tab. Click Filter and confirm that there is a checkmark
next to “Show read-only attributes: Constructed and Backlinks”.
4. Scroll to msDS-PSOApplied.
5. Click OK.
Using a command-line interface
psomgr.exe -effective <User DN>
Using PowerShell
Get-ADUser -Identity "<UserDN>" -Properties msDS-ResultantPSO |↵
FL Name, msDS-ResultantPSO
9.31. Viewing the Effective PSO for a User | 345
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
371
|
Discussion
Within a Windows Server 2008 or later domain, each user object contains a constructed
backlink attribute called msDS-ResultantPSO that indicates which PasswordSetting
sObject is in effect for that user. The precedence rules for PasswordSettingsObjects
are as follows:
1. If a PSO has been applied directly to the user object, it will take precedence. If
multiple PSOs have been applied to a single user, the following tiebreakers will be
used:
• A PSO with a lower-numbered Precedence attribute (e.g., 5) will be applied over
a higher-numbered one (e.g., 50).
• If multiple PSOs have been configured with the same Precedence attribute, the
PSO with the lowest GUID will take final precedence.
2. If no PSOs have been applied directly to the user, any PSO that has been applied to
a group that the user is a member of, whether directly or indirectly, will be applied.
The same tiebreakers will be used here as in rule 1.
3. If no PSOs have been applied to the user or any groups that the user is a member
of, the default domain PSO will be applied.
See Also
Recipe 9.29; 3.1.1.4.5.36 msDSResultantPSO
346 | Chapter 9: Group Policy Objects
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
372
|
CHAPTER 10
Schema
10.0. Introduction
The Active Directory schema contains the blueprint for how objects are structured and
secured, what data they can contain, and even how they can be viewed. Having a good
understanding of the schema is paramount for any Active Directory administrator,
designer, or architect. Understanding key concepts, such as class inheritance, class types,
attribute syntax, and attribute indexing options is critical to being able to adequately
design an Active Directory infrastructure and should be considered mandatory for any
developer who is writing applications or automation scripts that utilize Active Directory.
If you are one of the lucky few who is designated as a schema administrator (i.e., a
member of the Schema Admins group), then the importance of the schema is already
well known to you. This chapter serves as a guide to accomplishing many of the dayto-day tasks of schema administrators. For a more in-depth discussion of the schema,
we suggest reading Active Directory, Fifth Edition, by Brian Desmond et al. (O’Reilly).
The Anatomy of Schema Objects
An interesting feature of Active Directory not common among other LDAP imple‐
mentations is that the schema is stored within Active Directory itself as a set of objects.
This means that you can use similar interfaces and programs to manage the schema as
you would any other type of object without any need to shut down or restart Active
Directory.
All schema objects are stored in the Schema container (cn=schema,cn=configura
tion,<ForestRootDN>). The schema consists of two classes of objects, classSchema and
attributeSchema. Not surprisingly, the classSchema objects define classes and attrib
uteSchema objects define attributes. The Schema container contains a third type of object
called subSchema, also known as the abstract schema, which is defined in the LDAP
347
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
373
|
version 3 specification (RFC 2251). There is only a single subSchema object in the Schema
container, named cn=Aggregate, and it contains a summary of the entire schema.
Table 10-1 and Table 10-2 contain useful attributes of classSchema objects and attrib
uteSchema objects, respectively.
Table 10-1. Attributes of classSchema objects
Attribute Description
adminDescription Description of the class.
auxiliaryClass Multivalued attribute containing any auxiliary classes defined for the class.
cn Relative distinguished name of the class.
defaultHidingValue Boolean that determines whether objects of this class are hidden by default
in administrative GUIs.
defaultSecurityDescriptor Default security descriptor applied to objects of this class.
governsID OID for the class.
isDefunct Boolean that indicates whether the class is defunct (i.e., deactivated).
lDAPDisplayName Name used when referencing the class in searches or when instantiating or
modifying objects of this class.
mayContain Multivalued attribute that contains a list of attributes that can be optionally
set on the class.
mustContain Multivalued attribute that contains a list of attributes that must be set on the
class.
objectClassCategory Integer representing the class’s type. Can be one of 1 (structural), 2(abstract),
3 (auxiliary), or 0 (88).
possibleInferiors Multivalued list of other object classes this object can contain.
possSuperiors Multivalued list of object classes this object can be subordinate to.
rDNAttID Naming attribute (i.e., RDN) of instances of the class.
schemaIDGUID GUID of the class.
showInAdvancedViewOnly Boolean that indicates whether instances of this class should be shown only
in Advanced mode in the administrative GUIs.
subClassOf Parent class.
systemAuxiliaryClass Multivalued attribute containing any auxiliary classes defined for the class.
This can be modified only internally by Active Directory.
systemFlags Integer representing additional properties of the class.
systemMayContain Multivalued attribute that contains a list of attributes that can be optionally
set on the class. This can be modified only internally by Active Directory.
systemMustContain Multivalued attribute that contains a list of attributes that must be set on the
class. This can be modified only internally by Active Directory.
systemPossSuperiors Multivalued list of object classes this object can be subordinate to. This can
be modified only internally by Active Directory.
348 | Chapter 10: Schema
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
374
|
Table 10-2. Attributes of attributeSchema objects
Attribute Description
adminDescription Description of the attribute.
attributeID OID for the attribute.
attributeSecurityGUID GUID of the property set (if any) that an attribute is a member of.
attributeSyntax OID representing the syntax of the attribute. This is used in conjunction with oMSyntax to
define a unique syntax.
cn Relative distinguished name of the attribute.
isDefunct Boolean that indicates if the attribute is defunct (i.e., deactivated).
isMemberOfPartialAt
tributeSet
Boolean that indicates if the attribute is a member of the partial attribute set (i.e., the global
catalog).
isSingleValued Boolean that indicates whether the attribute is single-valued or multivalued.
linkID If populated, will contain an integer that represents a link (either forward or backward) to
another attribute.
lDAPDisplayName Name used when referencing the attribute in searches or when populating it on objects. Note
that this value may not be the same as cn.
oMSyntax An integer representing the OSI Abstract Data Manipulation (OM) type of the attribute. This is
used in conjunction with attributeSyntax to determine a unique syntax for the attribute.
schemaIDGUID GUID of the attribute.
searchFlags Integer representing special properties related to searching with the attribute. This includes
how the attribute is indexed and if it is used in ANR searches.
systemFlags Integer representing additional properties of the attribute.
10.1. Registering the Active Directory Schema
MMC Snap-in
Problem
You want to use the Active Directory Schema MMC snap-in for the first time on an
administrative computer.
Solution
Before you can use the Active Directory Schema MMC snap-in, you have to register
the .dll associated with it. This can be done with the regsvr32 utility using the following
command:
> regsvr32 schmmgmt.dll
If the command is successful, you’ll see the following message:
DllRegisterServer in schmmgmt.dll succeeded.
10.1. Registering the Active Directory Schema MMC Snap-in | 349
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
375
|
Discussion
Most of the Active Directory MMC snap-ins do not require that you manually register
the associated .dll. Microsoft requires this with the Active Directory Schema snap-in,
however, due to the sensitive nature of modifying the schema. This doesn’t actually do
much to prevent users from using it, but at least it isn’t available by default. And re‐
gardless, only members of the Schema Admins group have permission to modify the
schema anyway, so making this snap-in available should not pose any risk.
The schmmgmt.dll file is installed as part of the AD DS Tools feature (specifically, the
AD DS Snap-Ins and Command-Line Tools subfeature), or else it is installed by default
on domain controllers when they are first promoted. If you want to use the Schema
snap-in on a domain member server or workstation machine and you have not installed
the feature, you’ll need to specify the full path to schmmgmt.dll when using regsvr32.
10.2. Generating an OID to Use for a New Class
or Attribute
Problem
You want to generate an OID to use with a new class or attribute that you intend to add
to the schema.
Solution
To implement schema extensions for production use, you should use an OID from your
company or organization’s OID branch. To determine whether your company already
has an assigned OID, see these sites:
• www.iana.org/assignments/enterprise-numbers
• www.alvestrand.no/objectid/
If your organization does not have an assigned OID, go to your country’s national reg‐
istry to request one.
Once you have a base OID, you can create branches from that OID however you want.
For example, if you had a base OID of 1.2.3.4, you could start new class OIDs under
1.2.3.4.1 and new attributes under 1.2.3.4.2. In that case, the first class OID you would
create would be 1.2.3.4.1.1, and the first attribute OID would be 1.2.3.4.2.1.
Discussion
An OID is nothing more than a string of numbers separated by periods (.). OIDs were
initially defined by the ITU-T in X.208 and have been used to uniquely identify a variety
350 | Chapter 10: Schema
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
376
|
of things, including SNMP MIB objects and LDAP schema classes and attributes. OIDs
are hierarchical, and the national registries are responsible for managing and assigning
OID branches.
10.3. Extending the Schema
Problem
You want to extend the schema to support new classes and attributes in Active Directory.
Solution
Extending the schema is a straightforward process that consists of adding new classes
or attributes, or modifying existing ones in the schema. While extending the schema is
not hard, due to the sensitive nature of the schema you should implement a schema
extension process that thoroughly tests any extensions before you put them in your
production forest. Here is a suggested summary of what your schema extension process
should entail:
1. Meet with staff and determine whether there is a business justification for inte‐
grating the application with Active Directory. Determine whether there are any
existing attributes that would fulfill the desired requirements instead.
2. Examine the extensions and determine what impact, if any, they will have on your
Active Directory environment (e.g., adding an attribute to the global catalog).
3. Update your test environment with the extensions and then test your core appli‐
cations and services.
4. Document the extensions.
5. Extend the schema in your production Active Directory.
For more information on defining a schema extension process, see Active Directory,
Fifth Edition, by Brian Desmond et al. (O’Reilly).
Discussion
One thing to be cautious of when developing a schema extension process is not to make
it an overly bureaucratic process that can require months to complete. At the same time,
you want to ensure that any schema changes that you make are well thought out, tested,
and documented thoroughly to avoid encountering issues later. While some organiza‐
tions may want to strictly limit schema extensions, there is nothing inherently bad about
properly extending the schema.
10.3. Extending the Schema | 351
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
377
|
See Also
Recipe 10.6 for adding a new attribute; Recipe 10.8 for adding a new class; “Extending
the schema”
10.4. Preparing the Schema for an Active Directory
Upgrade
Problem
You want to prepare the Active Directory schema for an Active Directory upgrade.
Solution
From a graphical user interface
To prepare your Active Directory forest for a Windows upgrade, do the following:
1. Log on to a server or a domain controller in the AD forest. Copy the installation
media of the new Windows operating system to the domain controller.
2. Open an elevated command prompt and navigate to the installation media. For
example, if the installation media is at the root of the D:\ volume, you would navigate
to D:\support\adprep.
3. Run the command adprep /forestprep. Read the warning message that appears
and press C, followed by Enter.
To determine whether adprep /forestprep has completed, see Recipe 2.12.
To extend an Active Directory domain to prepare for an upgrade, follow these steps:
1. Log on to a server or domain controller in the domain. Copy the installation media
of the new Windows operating system to the domain controller.
2. Open an elevated command prompt and navigate to the installation media. For
example, if the installation media is at the root of the D:\ volume, you would navigate
to D:\support\adprep.
3. Run the command adprep /domainprep. Read the warning message that appears
and press C, followed by Enter.
Discussion
Major upgrades to the Windows operating system on domain controllers will usually
require that the Active Directory schema be extended with new classes and attributes.
352 | Chapter 10: Schema
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
378
|
To automate this process, Active Directory includes the adprep utility to perform these
modifications. adprep needs to be run once for the entire forest using the /forest
prep switch and once for each domain that will be upgraded using the /domainprep
switch. In the case of a Windows Server 2012 upgrade, you can view the schema exten‐
sions that will be performed by this utility by looking at the .ldf files in the \support
\adprep directory in the installation media. These files contain LDIF entries for adding
and modifying new and existing classes and attributes. Since the /forestprep process
extends and modifies the schema, you must perform this task using credentials that
belong to both the Schema Admins and Enterprise Admins groups.
After /forestprep has completed, /domainprep will create new containers and objects
within each Domain NC, as well as modify ACLs on some objects and the behavior of
the Everyone security principal. Before you can run /domainprep, you need to ensure
that the updates from /forestprep have replicated to all domain controllers in the forest
using the method described in this recipe. /domainprep needs to have connectivity to
the Infrastructure Master of the domain, using Domain Admin credentials.
One major change that Windows Server 2012 introduced is the integration of adprep
into the domain controller promotion process. For some environments, this is seen as
a nifty new feature that saves time and hassle. For large enterprise environments, this
is sometimes seen as a dangerous thing and a potential violation of change control. Some
enterprise environments are opting to prepare the forest and domain ahead of time,
prior to the promotion of the first Windows Server 2012 server.
See Also
Recipe 3.9 for more on verifying the promotion of a domain controller
10.5. Documenting Schema Extensions
Problem
You want to document your schema extensions.
Solution
There are several different ways you can document schema extensions. If you require
LDIF files of the schema extensions before you extend the schema, you can use the files
themselves as a simple self-documenting system. You can put comments in LDIF files
by putting # at the beginning of a line, or else use the AD Schema Analyzer available
with Active Directory Lightweight Directory Service (AD LDS). We recommend a
combination of these options, and recommend that any company that needs to extend
its schema include LDIF files, regardless of whether you use that method to actually
extend the schema.
10.5. Documenting Schema Extensions | 353
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
379
|
The AD Schema Analyzer is a useful tool that can document your existing schema, as
well as create a file to help you modify the schema. To use the Schema Analyzer to create
an LDIF file, do the following:
1. Open a command prompt and navigate to the Windows\ADAM directory. Run the
program adschemaanalyzer.exe from the command prompt.
2. Click File→Load target schema. To load the current Active Directory schema, enter
your username, password, and domain name, and then click OK.
3. Place a checkmark next to each class, attribute, and property set that you wish to
export.
4. Click File→Create LDIF file. Enter a path and name of the file to export, and click
Save.
Discussion
There are no hard-and-fast rules for documenting schema extensions. Documenting
schema extensions in some fashion, even a rudimentary one, should be a requirement
of any schema extension process you adopt. If you have the resources and time, you can
even develop a much more elaborate documentation system.
See Also
RFC 2849 (The LDAP Data Interchange Format (LDIF)—Technical Specification);
“Windows Server 2012: Changes to Adprep.exe”
10.6. Adding a New Attribute
Problem
You want to add a new attribute to the schema.
Solution
Using a graphical user interface
1. Open the Active Directory Schema snap-in.
2. In the left pane, expand Active Directory Schema, and then right-click on the At‐
tributes folder and select Create Attribute.
3. Click the Continue button to confirm that you want to extend the schema.
4. Enter the information for the new attribute.
354 | Chapter 10: Schema
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
380
|
5. Click OK.
Using a command-line interface
You can create new attributes by using ldifde and an LDIF file that contains the properties
to be set on the attribute. The following code shows a sample LDIF file called cre
ate_attr.ldf that creates an attribute called adatum-LanguagesSpoken:
dn: cn=adatum-LanguagesSpoken,cn=schema,cn=configuration,<ForestRootDN>
changetype: add
objectclass: attributeSchema
lDAPDisplayName: adatumLanguagesSpoken
attributeId: 1.3.6.1.4.1.999.1.1.28.3
oMSyntax: 20
attributeSyntax: 2.5.5.4
isSingleValued: FALSE
searchFlags: 1
description: "Languages a user speaks"
Then run the following command:
> ldifde -v -i -f create_attr.ldf
You can also use AdMod to add a schema attribute as follows:
> admod -schema -rb cn=adatumLanguagesSpoken
objectClass::attributeSchema
lDAPDisplayName::adatumLanguagesSpoken
attributeId::1.3.6.1.4.1.999.1.1.28.3
omSyntax::20
attributeSyntax::2.5.5.4
isSingleValued::FALSE
searchFlags::1
description::"Languages a user speaks"
-add
Using PowerShell
To create a schema attribute by using PowerShell, use the following syntax:
New-ADObject -Name "Custom60" -Type "attributeSchema" -OtherAttributes↵
@{distinguishedName="cn=Custom60,cn=Schema,cn=Configuration,<ForestRootDN>"↵
;LDAPDisplayName="Custom60";attributeId="1.3.6.1.4.1.999.1.1.28.3";oMSyntax="20"↵
;attributeSyntax="2.5.5.4";isSingleValued=$false↵
;Description="Custom class #60";searchFlags="1"}
Discussion
The GUI solution requires that the .dll file for the Active Directory Schema snap-in has
been registered. See Recipe 10.1 for more information.
10.6. Adding a New Attribute | 355
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
381
|
To create an attribute, you need to add an attributeSchema object to the Schema con‐
tainer. Typically, when you extend the schema you perform several additions or mod‐
ifications at once. The order of your extensions is very important. You can’t create a
class, assign an attribute, and then create the attribute; you obviously need to create the
attribute before it can be assigned to the class. Even if you create the attribute before
you assign it to a class, you must reload the schema before doing the class assignment.
Reloading the schema is described in more detail in Recipe 10.23.
Most of the attributes that can be set on attributeSchema objects are pretty straight‐
forward, but a couple of them require a little explanation. The attributeSyntax and
oMSyntax attributes together define the syntax, or the type of data that can be contained
in the attribute. Table 10-3 shows the possible combinations of these two attributes and
the resultant syntax.
Table 10-3. attributeSyntax and oMSyntax combinations
Name attribu
teSyntax
oMSyn
tax
Description
AccessPointDN 2.5.5.14 127 Type of distinguished name taken from X.500.
Boolean 2.5.5.8 1 TRUE or FALSE value.
CaseExactString 2.5.5.3 27 Case-sensitive string.
CaseIgnoreString 2.5.5.4 20 Case-insensitive string.
DirectoryString 2.5.5.12 64 Case-insensitive Unicode string.
DN 2.5.5.1 127 String representing a distinguished name.
DNWithBinary 2.5.5.7 127 Octet string that has the following format: B:CharCount:Bina
ryValue:ObjectDN, where CharCount is the number of
hexadecimal digits in BinaryValue, BinaryValue is the
hexadecimal representation of the binary value, and ObjectDN is a
distinguished name.
DNWithString 2.5.5.14 127 Octet string that contains a string value and a DN. A value with this
syntax has the following format: S:CharCount:StringVal
ue:ObjectDN, where CharCount is the number of characters in
the StringValue string and ObjectDN is a distinguished name
of an object in Active Directory.
Enumeration 2.5.5.9 10 Defined in X.500 and treated as an integer.
GeneralizedTime 2.5.5.11 24 Time-string format defined by ASN.1 standards. See ISO 8601 and X.
680.
IA5String 2.5.5.5 22 Case-sensitive string containing characters from the IA5 character set.
Integer 2.5.5.9 2 32-bit integer.
Integer8 2.5.5.16 65 64-bit integer, also known as a large integer.
NTSecurityDescrip
tor
2.5.5.15 66 Octet string that contains a security descriptor.
NumericString 2.5.5.6 18 String that contains digits.
356 | Chapter 10: Schema
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
382
|
Name attribu
teSyntax
oMSyn
tax
Description
OctetString 2.5.5.10 4 Array of bytes used to store binary data.
OID 2.5.5.2 6 String that contains digits (0–9) and decimal points (.).
ORName 2.5.5.7 127 Taken from X.400; used for X.400 to RFC 822 map ping.
PresentationAd
dress
2.5.5.13 127 String that contains OSI presentation addresses.
PrintableString 2.5.5.5 19 Case-sensitive string that contains characters from the printable
character set.
ReplicaLink 2.5.5.10 127 Used by Active Directory internally.
Sid 2.5.5.17 4 Octet string that contains a security identifier (SID).
UTCTime 2.5.5.11 23 Time-string format defined by ASN.1 standards.
The searchFlags attribute is a bit flag that defines special properties related to searching
with the attribute. Table 10-4 contains the values that can be set for this attribute. The
values are cumulative, so to index an attribute and include it in ANR searches, you would
set a value of 5 (1 + 4).
Table 10-4. searchFlags bit values
Value Description
1 Index over attribute. See Recipe 10.10 for more information.
2 Index over container and attribute.
4 Include as part of Ambiguous Name Resolution (ANR). Should be used in addition to 1. See Recipe 10.12for more information.
8 Preserve attribute in tombstone objects. This will ensure that the value of a particular attribute will be retained when the
object is tombstoned, so that it will be repopulated automatically if you need to reanimate the object.
16 Copy attribute when duplicating an object. See Recipe 10.11 for more information.
32 Create a tuple index for this attribute. This improves the response time for searches that put a wildcard in front of the
search string for the attribute (e.g., givenname=*on).
64 Create an index on which to assist with VLV performance.
128 Set the confidential bit on this attribute, which requires normal users to be assigned additional permissions to be able to
read its contents.
256 Disable security auditing for the attribute. Applicable to Windows Server 2008 and later.
512 Attribute should be added to the Read-Only Filtered Attribute Set (RO-FAS), preventing the attribute from being replicated
to any RODCs in the environment.
See Also
Recipe 4.15 for setting a bit flag; Recipe 10.8 for adding a new class; Recipe 10.23 for
reloading the schema
10.6. Adding a New Attribute | 357
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
383
|
10.7. Viewing an Attribute
Problem
You want to view the properties of an attribute.
Solution
Using a graphical user interface
1. Open the Active Directory Schema snap-in.
2. In the left pane, expand Active Directory Schema and then click on the Attributes
folder.
3. In the right pane, double-click the attribute you want to view.
4. Click on each tab to view the available properties.
Using a command-line interface
In the following command, replace <AttrCommonName> with the common name (not
the LDAP display name) of the attribute you want to view:
> dsquery * cn=schema,cn=configuration,<ForestRootDN> -scope onelevel -attr *↵
-filter "(&(objectcategory=attributeSchema)(cn=<AttrCommonName>))"
For example, to view the properties of the Surname attribute in the adatum.com domain,
you would run the following command:
> dsquery * cn=schema,cn=configuration,dc=adatum,dc=com -scope onelevel -attr *↵
-filter "(&(objectcategory=attributeSchema)(cn=surname))"
You can also use AdFind to view the properties of an attribute, as follows:
> adfind -schema -f (ldapdisplayname=<AttributeName>)
You can also use shortcut syntax for this command, as follows:
> adfind -sc s:<AttributeName>
Using PowerShell
You can view the properties of a schema attribute using PowerShell, as follows:
Get-ADObject -Identity "<ObjectDN>" -Properties * | FL
For example, to view the properties of the Surname attribute, you would run the fol‐
lowing PowerShell command:
Get-ADObject -Identity "cn=surname,cn=schema,cn=configuration,dc=adatum,dc=com"↵
-Properties * | FL
358 | Chapter 10: Schema
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
384
|
Discussion
The GUI solution requires that the .dll file for the Active Directory Schema snap-in has
been registered. See Recipe 10.1 for more information.
In the CLI solutions, we mention that you need to specify the common name (or cn) of
the attribute you want to view. The common name is a source of confusion for many
people. For example, the surname attribute has the following distinguished name in the
adatum.com forest:
cn=surname,cn=schema,cn=configuration,dc=adatum,dc=com
The problem is that most applications refer to attributes by their LDAP display name
as defined in the lDAPDisplayName attribute for the attributeSchema object, which is
typically different from the cn attribute. As an example, the surname attribute uses
surname for its common name (cn), but sn for its LDAP display name (lDAPDisplay
Name).
In the CLI solution, to use the LDAP display name instead of cn when using DSQuery,
simply change (cn=<AttrCommonName>) to (lDAPDisplayName= <AttrLDAPName>).
AdFind includes the shortcut adfind -sc s:<name>, which will check both the LDAP
Display Name and the cn automatically. Additionally, this shortcut will decode various
properties when it produces its output.
One attribute of note that is defined on attributeSchema objects is the systemFlags
bit flag, which is used to define a few miscellaneous properties about an attribute.
Table 10-5 contains the bits associated with systemFlags. The values are cumulative,
so a value of 17 (1 + 16) would indicate that the attribute is part of the base Active
Directory installation and is not replicated.
Table 10-5. systemFlags bit values
Value Description
1 Not replicated among domain controllers.
4 Dynamically constructed by Active Directory.
16 Part of the base Active Directory installation. This value cannot be set.
See Also
Recipe 4.2 for viewing the attributes of an object; Recipe 4.12 for searching with a bitwise
filter
10.7. Viewing an Attribute | 359
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
385
|
10.8. Adding a New Class
Problem
You want to add a new class to the schema.
Solution
Using a graphical user interface
1. Open the Active Directory Schema snap-in.
2. In the left pane, expand Active Directory Schema and then right-click on the Classes
folder and select “Create Class”.
3. Click the Continue button to confirm that you want to extend the schema.
4. Enter the information for the new class and click Next.
5. Enter any mandatory and optional attributes and click Finish.
Using a command-line interface
You can create new classes by using ldifde and an LDIF file that contains the properties
to be set on the class. The following code shows a sample LDIF file called cre
ate_class.ldf that creates a class called adatum-SalesUser:
dn: cn=adatum-SalesUser,cn=schema,cn=configuration,<ForestRootDN>
changetype: add
objectclass: classSchema
lDAPDisplayName: adatum-SalesUser
governsId: 1.3.6.1.4.1.999.1.1.28.4
objectClassCategory: 3
subClassOf: top
description: Auxiliary class for Sales user attributes
adminDescription: Auxiliary class for Sales user
attributes
mayContain: adatum-Building
mayContain: adatum-Theatre
Then run the following command:
> ldifde -v -i -f create_class.ldf
You can also add a new class using AdMod, as follows:
> admod -schema -rb cn=adatum-SalesUser↵
objectclass::classSchema lDAPDisplayName::adatum-SalesUser↵
governsId::1.3.6.1.4.1.999.1.1.28.4 objectClassCategory::3↵
subClassOf::top↵
description::"Auxiliary class for Sales user"↵
360 | Chapter 10: Schema
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
386
|
adminDescription::"Auxiliary class for Sales user"↵
mayContain::adatum-Building;adatum-Theatre↵
-add
Using PowerShell
To create a schema class by using PowerShell, use the following syntax:
New-ADObject -Name "adatum-SalesUser " -Description "Custom Class"↵
-Type "classSchema" -OtherAttributes↵
@{distinguishedname="cn=Custom24,cn=Schema,cn=Configuration,<ForestRootDN>"↵
;LDAPDisplayName="adatum-SalesUser";governsId="1.3.6.1.4.1.999.1.1.28.4"↵
;objectCategory="3";subClassOf="top"↵
;adminDescription="Auxilliary class for Sales user attributes"}
Discussion
To create a new class, you need to create a classSchema object in the Schema container.
The important attributes to set include:
governsId
Defines the OID for the class
objectClassCategory
Defines the class type
subClassOf
Defines the parent class
mayContain and mustContain
Define any optional and mandatory attributes for instantiated objects of the class
The lDAPDisplayName also needs to be set and should be equal to the common name
(cn) as a general rule. Even though many of the default classes do not use the same name
for the common name and LDAP display name, using the same name is highly recom‐
mended to avoid confusion when referencing the class. Another good practice is to set
the schemaIDGUID of the class.
See Also
See Recipe 10.0 for attributes of classSchema objects; Recipe 10.2 for generating an
OID; Recipe 10.16 for more on object class type; Recipe 10.18 for setting the default
security for a class; Recipe 10.23 for reloading the schema cache
10.8. Adding a New Class | 361
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
387
|
10.9. Viewing a Class
Problem
You want to view the attributes of a class.
Solution
Using a graphical user interface
1. Open the Active Directory Schema snap-in.
2. In the left pane, expand Active Directory Schema and then click on the Classes
folder.
3. In the right pane, double-click the class you want to view.
4. Click on each tab to view the available properties.
Using a command-line interface
In the following command, replace <ClassCommonName> with the common name (not
LDAP display name) of the class you want to view:
> dsquery * cn=<ClassCommonName>,cn=schema,cn=configuration,<ForestRootDN>↵
-scope base -attr *
You can also use AdFind to view the properties of a class, as follows:
> adfind -schema -rb cn=<ClassCommonName>
In addition, you can use shortcut syntax for this command, as follows:
> adfind -sc s:<ClassCommonName or ClassLDAPDisplayName>
Using PowerShell
Get-ADObject -Identity "cn=<ClassName>,cn=schema,cn=configuration,↵
<ForestRootDN>" -Properties * | FL
Discussion
The GUI solution requires that the .dll file for the Active Directory Schema snap-in has
been registered. See Recipe 10.1 for more information.
See Table 10-1, at the beginning of this chapter, for a list of the important classSche
ma attributes and their descriptions.
362 | Chapter 10: Schema
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
388
|
See Also
Recipe 4.2 for viewing the attributes of an object
10.10. Indexing an Attribute
Problem
You want to index an attribute so that searches using that attribute are faster.
Solution
Using a graphical user interface
1. Open the Active Directory Schema snap-in.
2. In the left pane, expand Active Directory Schema and then click on the Attributes
folder.
3. In the right pane, double-click the attribute you want to index.
4. Check the box beside “Index this attribute.”
5. Click OK.
Using a command-line interface
You can index an attribute by using the ldifde utility and an LDIF file that contains the
following:
dn: cn=<AttrCommonName>,cn=schema,cn=configuration,<ForestRootDN>
changetype: modify
replace: searchFlags
searchFlags: 1
-
If the LDIF file were named index_attribute.ldf, you would run the following command:
> ldifde -v -i -f index_attribute.ldf
You can also enable the appropriate searchFlags value using admod, as follows:
> admod -schema -rb cn=<AttrCommonName> searchFlags::1
The CLI solution and the PowerShell solution assume that search
Flags wasn’t previously set; if a value is present, it just blindly overwrites
it. See Recipe 4.15 for a better solution that will enable the bit value you
want without overwriting any previous settings.
10.10. Indexing an Attribute | 363
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
389
|
Using PowerShell
To set the searchFlags bit value by using PowerShell, use the following syntax:
Set-ADObject "<AttributeDN>" -Replace @{"searchFlags"="1"}
Discussion
To index an attribute, you need to set bit 0 (0001) in the searchFlags attribute for the
attributeSchema object.
searchFlags is a bit-flag attribute that is used to set various properties related to
searching with the attribute. Table 10-5, earlier in this chapter, contains the various bit
flags that can be set with searchFlags. When setting searchFlags, you may often need
to set a couple of bits together. For example, all Ambiguous Name Resolution (ANR)
attributes must also be indexed, which means searchFlags should be set to 5 (1 + 4).
You can find the attributes that are indexed in the schema by using the following search
criteria:
Base
cn=Schema,cn=Configuration,<ForestRootDN>
Filter
(&(objectcategory=attributeSchema)(searchFlags:
1.2.840.113556.1.4.803:=1))
Scope
onelevel
Alternatively, to find attributes that aren’t indexed, change the previous search filter to
the following:
(&(objectcategory=attributeSchema)(!(searchFlags:1.2.840.113556.1.4.803:=1)))
Since Windows Server 2008, the objectClass attribute is now indexed
by default. This allows you to perform simpler searches by querying
directly against objectClass, rather than using the more complex
query of "(&(objectCategory=ABC)(objectClass=XYZ))". Note that
some searches require a more complex query as the results may differ
if only relying on the objectClass attribute.
You can also find indexed attributes using AdFind, as follows:
adfind -sc indexed
364 | Chapter 10: Schema
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
390
|
See Also
Recipe 4.15 for modifying a bit-flag attribute; Recipe 10.6 for adding a new attribute
10.11. Modifying the Attributes That Are Copied When
Duplicating a User
Problem
You want to add an attribute to the list of attributes that are copied when duplicating a
user with the ADUC snap-in.
Solution
Using a graphical user interface
1. Open the Active Directory Schema snap-in.
2. In the left pane, expand Active Directory Schema and then click on the Attributes
folder.
3. In the right pane, double-click the attribute you want to edit.
4. Check the box beside “Attribute is copied when duplicating a user.”
5. Click OK.
Using a command-line interface
You can cause an attribute to get copied when duplicating a user by using the ldifde
utility and an LDIF file that contains the following:
dn: cn=adatum-LanguagesSpoken,cn=schema,cn=configuration,<ForestRootDN>
changetype: modify
replace: searchFlags
searchFlags: 16
-
If the LDIF file were named add_dup_user_attr.ldf, you would run the following com‐
mand:
> ldifde -v -i -f add_dup_user_attr.ldf
You can also modify the searchFlags attribute using AdMod, as follows:
> admod -b <AttributeDN> searchFlags::16
10.11. Modifying the Attributes That Are Copied When Duplicating a User | 365
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
391
|
The CLI solution and the PowerShell solution assume that search
Flags wasn’t previously set; if a value is present, it just blindly overwrites
it. See Recipe 4.15 for a better solution that will enable the bit you want
without overwriting any previous settings.
Using PowerShell
To set the searchFlags bit value by using PowerShell, use the following syntax:
Set-ADObject "<AttributeDN>" -Replace @{"searchFlags"="16"}
Discussion
The GUI solution requires that the .dll file for the Active Directory Schema snap-in has
been registered. See Recipe 10.1 for more information.
The Active Directory Users and Computers snap-in queries the schema for the list of
attributes that should be copied whenever you right-click on a user and select Copy.
This flag is purely informational and does not impose any restrictions.
To find out which attributes are copied when duplicating a user, use the following search
criteria:
Base
cn=Schema,cn=Configuration,<ForestRootDN>
Filter
(&(objectcategory=attributeSchema)(searchFlags:
1.2.840.113556.1.4.803:=16))
Scope
onelevel
Alternatively, to find attributes that aren’t copied, change the previous search filter to
the following:
(&(objectcategory=attributeSchema)(!(searchFlags:1.2.840.113556.1.4.803:=16)))
You can also find a list of these attributes using AdFind, as follows:
adfind -sc copy
See Also
Recipe 4.15 for modifying a bit-flag attribute; Recipe 10.6 for adding a new attribute
366 | Chapter 10: Schema
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
392
|
10.12. Modifying the Attributes Included with ANR
Problem
You want to modify the attributes that are included as part of ANR.
Solution
Using a graphical user interface
1. To proceed, you must have first indexed the attribute.
2. Open the Active Directory Schema snap-in.
3. In the left pane, click on the Attributes folder.
4. In the right pane, double-click the attribute you want to edit.
5. Check the box beside Ambiguous Name Resolution (ANR).
6. Click OK.
Using a command-line interface
You can include an attribute as part of ANR by using the ldifde utility and an LDIF file
that contains the following:
dn: cn=adatum-LanguagesSpoken,cn=schema,cn=configuration,<ForestRootDN>
changetype: modify
replace: searchFlags
searchFlags: 5
-
If the LDIF file were named add_anr_attr.ldf, you’d run the following command:
> ldifde -v -i -f add_anr_attr.ldf
You can also modify the searchFlags attribute using AdMod, as follows:
> admod -b <AttributeDN> searchFlags::5
The CLI solution and the PowerShell solution assume that search
Flags wasn’t previously set; if a value is present, it just blindly overwrites
it. Check out Recipe 4.15 for a better solution that will enable the bit
you want without overwriting any previous settings.
Using PowerShell
To set the ANR bit value by using PowerShell, use the following syntax:
10.12. Modifying the Attributes Included with ANR | 367
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
393
|
Set-ADObject "<AttributeDN>" -Replace @{"searchFlags"="5"}
Discussion
ANR is an efficient search algorithm that allows for a complex search filter to be written
using a single comparison. For example, a search for (anr=Jim Smith) would translate
into the following query:
• An OR filter with every attribute in the ANR set against Jim Smith*
• A filter for givenName = Jim* and sn = Smith*
• A filter for givenName = Smith* and sn = Jim*
These filters are ORed together and then processed by Active Directory. Since all ANR
attributes are also indexed, the query return should come back quickly.
Here is a list of the default attributes that are included as part of ANR searches.
The LDAP display name of the attribute is shown first, with the common name in
parentheses:
• displayName (Display-Name)
• givenName (Given-Name)
• legacyExchangeDN (Legacy-Exchange-DN)
• msDS-AdditionalSamAccountName (ms-DS-Additional-Sam-Account-Name)
• physicalDeliveryOfficeName (Physical-Delivery-Office-Name)
• name (RDN)
• sAMAccountName (SAM-Account-Name)
• sn (Surname)
One requirement of any new ANR attribute is that the attribute must also be indexed.
ANR searches are intended to be very fast, so if a nonindexed attribute were added to
the set, it could dramatically impact the performance of the searches. Therefore, Active
Directory requires that each added attribute be indexed. The PowerShell solution can
be run for a nonindexed attribute, but the result will be that the attribute will be set to
index and will be set for ANR. The Active Directory Schema snap-in will show the ANR
option as grayed out unless an attribute is already set to be indexed. Once an attribute
is set to be indexed, the Active Directory Schema snap-in will allow the ANR option to
be enabled.
You can use adfind with the -stats+only switch to verify what the ANR expansion
actually looks like. You can find out which attributes are included in the ANR set by
using the following search criteria:
368 | Chapter 10: Schema
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
394
|
Base
cn=Schema,cn=Configuration,<ForestRootDN>
Filter
(&(objectcategory=attributeSchema)(searchFlags:
1.2.840.113556.1.4.803:=4))
Scope
onelevel
You can also find attributes that are included in ANR using AdFind, as follows:
adfind -sc anr
Alternatively, to find attributes that aren’t included in ANR, change the previous search
filter to the following:
(&(objectcategory=attributeSchema)(!(searchFlags:1.2.840.113556.1.4.803:=4)))
See Also
Recipe 4.15 for modifying a bit-flag attribute; Recipe 10.6 for adding a new attribute;
“Ambiguous Name Resolution for LDAP in Windows 2000”
10.13. Modifying the Set of Attributes Stored on a
Global Catalog
Problem
You want to add or remove an attribute in the global catalog.
Solution
Using a graphical user interface
1. Open the Active Directory Schema snap-in.
2. In the left pane, expand Active Directory Schema and then click on the Attributes
folder.
3. In the right pane, double-click the attribute you want to edit.
4. Check the box beside “Replicate this attribute to the Global Catalog” to add the
attribute to the global catalog, or uncheck to remove the attribute from the global
catalog.
5. Click OK.
10.13. Modifying the Set of Attributes Stored on a Global Catalog | 369
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
395
|
Using a command-line interface
You can add an attribute to the global catalog by using the ldifde utility and an LDIF file
that contains the following:
dn: cn=<AttrCommonName>,cn=schema,cn=configuration,<ForestRootDN>
changetype: modify
replace:
isMemberOfPartialAttributeSet
isMemberOfPartialAttributeSet: TRUE
-
If the LDIF file were named add_gc_attr.ldf, you would run the following command:
> ldifde -v -i -f add_gc_attr.ldf
You can also modify this property using AdMod, as follows:
> admod -schema -rb cn=<AttrCommonName> isMemberOfPartialAttributeSet::TRUE
Using PowerShell
To add an attribute to the Partial Attribute Set by using PowerShell, use the following
syntax:
Set-ADObject "<AttributeDN>" -Replace @{"isMemberOfPartialAttributeSet"=$True}
Discussion
The GUI solution requires that the .dll file for the Active Directory Schema snap-in has
been registered. See Recipe 10.1 for more information.
Each domain controller in a forest replicates a copy of the Domain naming context for
its own domain, as well as copies of the forest-wide Configuration and Schema parti‐
tions. However, domain controllers do not replicate Domain naming contexts for other
domains in the forest. When enabled as a global catalog server, a domain controller will
make partial, read-only replicas of all the objects in other domains in the forest.
Searching against the global catalog is useful when you need to perform a single search
across several naming contexts at once. The global catalog stores only a subset of each
object’s attributes, which is why it is considered a partial replica. Attributes stored in the
global catalog are considered part of the PAS. Any attributes that you add to the PAS
should be ones you’d want to use as part of global catalog searches that are not present
already.
You can add to the attributes that are stored in the global catalog by setting the isMem
berOfPartialAttributeSet attribute of an attributeSchema object to TRUE. Likewise,
to remove an attribute from the PAS, set isMemberOfPartialAttributeSet to FALSE
for the target attribute.
370 | Chapter 10: Schema
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.