index
int64 0
4.08k
| text
stringlengths 34
4.9k
⌀ | url
stringclasses 38
values |
|---|---|---|
196
|
Solution
The following solutions will enumerate all the objects directly under an OU. Refer to
“Discussion” section for more on how to display all objects under an OU regardless of
the number of objects involved.
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 Change Domain, enter the domain name, and click
OK.
3. In the left pane, browse to the OU you want to view.
4. The contents of the OU will be displayed in the right pane.
Using a command-line interface
To list the contents of an OU using the built-in DSQuery utility, use the following syntax:
> dsquery * "<OU DN>" -limit 0 -scope onelevel
You can also use AdFind, as follows:
> adfind -b "<OU DN>" -s one -dn
Using PowerShell
To enumerate the contents of the Users container in the adatum.com domain, run the
following command:
Get-ADObject -SearchBase "cn=users,dc=adatum,dc=com" -Filter *
Discussion
Using a graphical user interface
By default, ADUC will display only 2,000 objects. To view more than 2,000 objects, click
View→Filter Options. Then modify the maximum number of items displayed per folder.
Using a command-line interface
Using -limit 0, all objects under the OU will be displayed. If -limit is not specified,
100 objects will be shown by default. You can also specify your own number if you want
to display only a limited number of objects.
The -scope onelevel or -s one (for AdFind) option causes only direct child objects
of the OU to be displayed. Displaying all objects regardless of depth is referred to as the
5.4. Enumerating the Objects in an OU | 171
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
197
|
subtree scope, which is the default search scope for AdFind and DSQuery. If you want
to return all objects regardless of depth, including the OU being searched, simply omit
the -scope switch entirely.
To save on typing, you can use the -default switch with AdFind, which automatically
uses the Domain DN as its search base. You can use this in combination with the -rb
(Relative Base) switch, which will only require you to type in the relative DN of the OU
that you want to search. So to list the objects in the cn=Finance,dc=adatum,dc=com OU,
you can use the following abbreviated AdFind syntax:
> adfind -default -rb ou=Finance -s one -dn
Another option would be to use the -incldn switch, which will return objects that
contain a particular search string anywhere within the Distinguished Name. So speci‐
fying -incldn "ou=Finance" would return the cn=Finance,dc=adatum,dc=com OU, as
well as the cn=FinanceTemps,cn=Finance,dc=adatum,dc=com OU.
Using PowerShell
The command uses a default search scope of subtree, which will return the OU being
searched and all child objects recursively. To restrict the search to only the immediate
children of the OU, add the -searchscope 'onelevel' switch to the command.
See Also
Recipe 5.2
5.5. Deleting the Objects in an OU
Problem
You want to delete all child objects in an OU, but not the OU itself.
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 Change Domain, enter the domain name, and click
OK.
3. In the left pane, browse to and select the OU that contains the objects you want to
delete.
172 | Chapter 5: Organizational Units
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
198
|
4. Highlight all the objects in the right pane and press the Delete key on your keyboard.
5. Press F5 to refresh the contents of the OU. If objects still exist, repeat step 4.
Using a command-line interface
To delete all objects within an OU, but not the OU itself, you need to use the -subtree
and -exclude options with the dsrm command:
> dsrm "<OrgUnitDN>" -subtree -exclude
You can also perform this task by piping the results of an adfind query into admod, as
follows:
>adfind -default -rb ou=<OU Name> -s one -dsq | admod -unsafe -del
Using PowerShell
To delete the child objects within the Test OU without a confirmation, use the following
command:
Get-ADObject -SearchBase "ou=test,dc=adatum,dc=com" -Filter *↵
-SearchScope OneLevel | Remove-ADObject -Confirm:$False
Discussion
If you want to delete the objects in an OU and re-create the OU, you can delete the OU
itself, which will delete all child objects, or you could just delete the child objects. The
benefit to the latter approach is that you do not need to reconfigure the ACL on the OU
or relink any Group Policy Objects after you’ve re-created the OU.
See Also
Recipe 5.4 for enumerating objects in an OU; Recipe 5.6 for deleting an OU; MSDN:
IADsDeleteOps::DeleteObject
5.6. Deleting an OU
Problem
You want to delete an OU that is not protected from accidental deletion along with all
of the objects in it.
5.6. Deleting an OU | 173
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
199
|
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 Change Domain, enter the domain name, and click
OK.
3. In the left pane, browse to the OU you want to delete, right-click on it, and select
Delete.
4. Click Yes for the confirmation prompt.
5. If the OU contains child objects, you will be asked for confirmation again before
deleting it. Click Yes to continue.
Using a command-line interface
To delete an OU and all objects contained within, use the -subtree option with the dsrm
command. If you don’t use -subtree and the object you are trying to delete has child
objects, the deletion will fail:
> dsrm "<OrgUnitDN>" -subtree
You can also delete an OU and all of its contents using the following admod command:
> admod -b "<OrgUnitDN>" -del -treedelete
Using PowerShell
To delete an OU named Test and its contents without a confirmation prompt, run the
following command:
Remove-ADObject -Identity "ou=test,dc=adatum,dc=com" -Recursive -Confirm:$False
Discussion
Deleting OUs that do not contain objects is just like deleting any other type of object.
Deleting an OU that contains objects, however, requires a special type of delete opera‐
tion. The Tree Delete LDAP control (OID: 1.2.840.113556.1.4.805) must be used by the
application or script to inform AD to delete everything contained in the OU. All three
solutions in this case use the control behind the scenes, but if you were going to perform
the operation via an LDAP utility such as LDP, you would need to enable the control
first.
174 | Chapter 5: Organizational Units
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
200
|
In Windows Server 2008 R2 and Windows Server 2012, the Active Di‐
rectory Users and Computers console adds an option to the delete con‐
firmation prompt to use the Delete Subtree server control. By using the
control, you can delete all child objects in an OU, even if the objects are
protected from accidental deletion.
See Also
Recipe 4.4 for using LDAP controls; MSDN: IADsDeleteOps::DeleteObject
5.7. Moving the Objects in an OU to a Different OU
Problem
You want to move some or all of the objects in an OU to a different OU. You may need
to do this as part of a domain restructuring effort.
Solution
Using a graphical user interface
1. Open the ADUC snap-in (dsa.msc).
2. If you need to change domains, right-click on the Active Directory Users and
Computers node in the lefthand pane, select Change Domain, enter the domain
name, and click OK.
3. In the left pane, browse to and select the OU that contains the objects you want to
move.
4. Highlight the objects you want to move in the right pane, right-click on them, and
select Move.
5. Browse to and select the parent container you want to move the objects to, and then
click OK.
6. Press F5 to refresh the contents of the OU. If objects still exist, repeat steps 3–5.
Using a command-line interface
To move each object from one OU to another, you can pipe the results of an adfind
query into admod using the following syntax:
> adfind -b "<Old OU DN>" -s one -dsq | admod -move "<New OU DN>"
5.7. Moving the Objects in an OU to a Different OU | 175
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
201
|
Using PowerShell
To move all users from the Test OU to the Test2 OU using PowerShell, use the following
command:
Get-ADObject -Filter {(ObjectClass -eq "User") -and↵
(ObjectCategory -eq "Person")} -SearchBase "ou=test,dc=adatum,dc=com" |↵
Move-ADObject -TargetPath "ou=test2,dc=adatum,dc=com"
Discussion
When you move objects from one OU to another, you need to be aware of two significant
Active Directory design factors that can affect the behavior of the objects that you’re
moving: delegation and Group Policy Object inheritance.
The first factor to be aware of is delegation. As an administrator, you can delegate per‐
missions at the OU level so that specific users and groups can (or cannot) access or
modify information concerning the objects contained within that OU. When you move
an object from one OU to another, that object inherits the delegation settings from its
new parent OU. This means that a user or group who had rights to an object before it
was moved may no longer have rights to it afterward, and a user or group who did not
have rights to the object before may have been delegated rights to the destination OU.
You need to be aware of this setting to be sure that you do not allow or prevent object
access unintentionally. Active Directory security and delegation is discussed further in
Chapter 14.
The second factor to keep in mind is that of GPO inheritance. You can link a GPO at
the site, domain, or OU level; any child objects that you move to a new OU will cease
to receive the GPO settings that were applied to the old OU and will receive those settings
associated with the new OU instead (unless the GPO is linked to the source OU and the
destination OU).
The one exception to this would be if you were moving an object from a parent OU to
its child OU—for example, moving from ou=Finance,dc=adatum,dc=com to ou=Finan
ceTemps,ou=Finance,dc=adatum,dc=com. In this example, the rules of GPO inheri‐
tance would cause the moved objects to receive any GPO settings linked to the Finance
OU, followed by any GPO settings linked to the Finance Temps OU. Again, you need
to be certain that moving an object from one OU to another does not create any unin‐
tended effects.
You can use the Group Policy Management Console’s Resultant Set of
Policy (Modeling) Wizard to simulate the effect that the move will have
on objects within the originating OU before you actually perform the
move.
176 | Chapter 5: Organizational Units
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
202
|
Using a graphical user interface
If you want to move more than 2,000 objects at one time, you will need to modify the
default number of objects displayed, as described in the “Discussion” section of
Recipe 5.4.
Using a command-line interface
AdMod will move only 10 objects at a time by default. To move more objects than this,
you need to either specify the -safety xx option, where xx is the maximum number of
objects to modify, or else use -unsafe to move an unlimited number of objects.
See Also
Recipe 4.20 for moving objects; Recipe 5.4 for enumerating objects in an OU; MSDN:
IADsContainer::MoveHere
5.8. Moving an OU
Problem
You want to move an OU and all its child objects to a different location in the directory
tree. Note that this scenario covers OUs and child objects that are not protected from
accidental deletion.
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 Change Domain, enter the domain name, and click
OK.
3. In the left pane, browse to the OU you want to move.
4. Right-click on the OU and select Move.
5. Select the new parent container for the OU and click OK.
Using a command-line interface
You can move an OU from one location to another by using either DSMove or AdMod.
The DSMove syntax is as follows:
> dsmove "<OrgUnitDN>" -newparent "<NewParentDN>"
5.8. Moving an OU | 177
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
203
|
If you wish to move an OU with AdMod, use the following syntax:
> admod -b "<OrgUnitDN>" -move "<NewParentDN>"
Using PowerShell
To move the Test OU to the Test2 OU, use the following command:
Move-ADObject -Identity "ou=test,dc=adatum,dc=com"↵
-TargetPath "ou=test2,dc=adatum,dc=com"
Discussion
One of the benefits of Active Directory is the ability to structure and restructure data
easily. Moving an OU, even one that contains a complex hierarchy of other OUs and
objects, can be done without impacting the child objects.
If any applications have a dependency on the location of specific objects, you need to
ensure that either they are updated with the new location or, preferably, they reference
the objects by GUID, not by distinguished name.
You should also be mindful of the impact of inherited ACLs and the effect of any new
GPOs that are linked to the new parent OU. Keep in mind that any GPOs that were
already linked to the OU will stay intact, and the link will follow the OU to its new
location in the directory structure.
See Also
“Move an Organizational Unit”
5.9. Renaming an OU
Problem
You want to rename an organizational unit in your 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 Change Domain, enter the domain name, and click
OK.
3. In the left pane, browse to the OU you want to rename.
178 | Chapter 5: Organizational Units
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
204
|
4. Right-click on the OU and select Rename.
5. Type in the new name for the OU and press Enter.
Using a command-line interface
To rename an object using the built-in DSMove utility, use the following syntax:
> dsmove "<ObjectDN>" -newname "<NewName>"
To use admod, use the following:
> admod -b "<ObjectDN>" -rename "<NewName>"
Using PowerShell
You can rename the Test OU to Test2 by using the following PowerShell command:
Rename-ADObject -Identity "ou=test,dc=adatum,dc=com" -NewName "Test2"
Discussion
Before you rename an OU, ensure that none of your production applications references
it by name. You can make objects rename-safe by requiring all applications that must
store a reference to an object to use the GUID of the object, rather than the name. The
GUID (stored in the objectGUID attribute) is effectively unique within a forest and does
not change when an object is renamed.
Using a command-line interface
The two parameters needed to rename an object are the original DN of the object and
the new RDN (-newname). The -s option can also be used to specify a server name to
work against.
See Also
Recipe 4.23; MSDN: IADsContainer::MoveHere
5.10. Modifying an OU
Problem
You want to modify one or more attributes of an OU.
Solution
The following examples set the description (description) attribute for the Finance OU.
5.10. Modifying an OU | 179
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
205
|
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 Change Domain, enter the domain name, and click
OK.
3. In the left pane, browse to the OU you want to modify.
4. Right-click on the OU and select Properties.
5. Modify the Description field and then click OK.
Using a command-line interface
To modify an object using AdMod, you’ll use the following general syntax:
> admod -b <ObjectDN> <attribute>:<operation>:<value>
For example, you can add a description to an OU object using the following syntax:
> admod -b cn="ou=Finance,dc=adatum,dc=com" description::"Finance Department"
You can modify a limited number of object types with DSMod. Run dsmod /? from a
command line for more details.
Using PowerShell
Set-ADObject -Identity "ou=finance,dc=adatum,dc=com" -Description↵
"Finance Department"
Discussion
Modifying the attributes of an OU is a relatively straightforward process that’s similar
to modifying other types of objects within Active Directory. You can modify most at‐
tributes of an OU using the Active Directory Computers and Users MMC snap-in, but
some attributes will be available for editing only by using ADSI Edit or a command-line
or scripting utility.
See Also
MSDN: IADs::Put; MSDN: IADs::PutEx; MSDN: IADs::SetInfo; MSDN: ADS_ PROP‐
ERTY_OPERATION_ENUM
180 | Chapter 5: Organizational Units
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
206
|
5.11. Determining Approximately How Many Child
Objects an OU Has
Problem
You want to quickly determine a rough approximation of how many child objects, if
any, an OU contains.
Solution
Using a graphical user interface
1. Open LDP.
2. From the Menu, select Browse→Search.
3. For Base DN, enter <OrgUnitDN>.
4. For Filter, enter (objectclass=*).
5. For Scope, select Base.
6. Click the Attributes input area and enter msDS-Approx-Immed-Subordinates for
attributes.
7. Click Run.
The results will be displayed in the righthand pane.
Another option would be to run a search using the onelevel scope and
count the number of objects returned by the query. In LDP you can
suppress the display of results so that it displays only the number of
objects returned rather than displaying the specifics of each item.
Using a command-line interface
You can retrieve the number of child objects that are contained in an OU using either
DSQuery or AdFind. To perform this task using DSQuery, use the following syntax:
> dsquery * "<OrgUnitDN>" -scope base -attr msDS-Approx-Immed-Subordinates
The syntax for AdFind is as follows:
> adfind -b "<OrgUnitDN>" -s base msDS-Approx-Immed-Subordinates
5.11. Determining Approximately How Many Child Objects an OU Has | 181
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
207
|
Using PowerShell
You can retrieve the number of child objects that are contained in an OU by using the
following PowerShell command:
Get-ADObject -SearchBase "ou=test,dc=adatum,dc=com" -Filter * |↵
Measure-Object | FL Count
Discussion
The msDS-Approx-Immed-Subordinates attribute was introduced in Windows Server
2003. It contains the approximate number of direct child objects in a container or or‐
ganizational unit. Note that this is an approximation and can be off by 10% or more,
sometimes significantly more, of the actual total for large containers. (For instance, we
ran this query for a container with 2,008 objects in it that reported a value of 1306 for
the msDS-Appox-Immed-Subordinates attribute.) The main reason for adding this at‐
tribute was to give applications an idea of the rough order of magnitude of how many
objects a container has so that it can display them accordingly.
msDS-Approx-Immed-Subordinates is a constructed attribute—that is, the value is not
actually stored in Active Directory like other attributes. Rather, Active Directory com‐
putes the value when an application asks for it.
Using PowerShell
The PowerShell solution relies on the Measure-Object cmdlet, which counts the num‐
ber of objects. The PowerShell solution will return an accurate count of objects, which
makes it the best choice when you need more accuracy than an estimate.
See Also
MSDN: GetInfoEx
5.12. Delegating Control of an OU
Problem
You want to delegate administrative access of an OU to allow a group of users to manage
objects in the OU.
Solution
Using a graphical user interface
1. Open the ADUC snap-in (dsa.msc).
182 | Chapter 5: Organizational Units
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
208
|
2. If you need to change domains, right-click on Active Directory Users and Com‐
puters in the left pane, select Change Domain, enter the domain name, and click
OK.
3. In the left pane, browse to and select the target OU, and then select Delegate Control.
4. Click Next and then click Add to select the users and/or groups to delegate control.
Click OK to close the selection window and then click Next.
5. Select the type of task to delegate to the users or groups you selected in step 4 and
then click Next.
6. Click Finish.
Using a command-line interface
ACLs can be set via the command line with the dsacls utility. See Recipe 14.12 for more
information.
Discussion
Although you can delegate control of an OU to a particular user, it is almost universally
a better practice to use a group instead. Even if there is only one user to delegate control
to, you should create a group, add that user as a member, and use that group in the ACL.
That way, in the future when you have to replace that user with someone else, you can
simply make sure the new person is in the correct group instead of modifying ACLs
again. The Delegation of Control Wizard is discussed further in Recipe 14.5.
See Also
Recipe 14.12 for changing the ACL on an object; Recipe 14.5
5.13. Assigning or Removing a Manager for an OU
Problem
You want to assign or remove a manager for an OU.
Solution
Using a graphical user interface
1. Open the ADUC snap-in (dsa.msc).
5.13. Assigning or Removing a Manager for an OU | 183
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
209
|
2. If you need to change domains, right-click on Active Directory Users and Com‐
puters in the left pane, select Change Domain, enter the domain name, and click
OK.
3. Locate the OU in the left pane and then right-click on the OU and select Properties.
4. Select the Managed By tab.
5. Click the Change button.
6. Locate the group or user to delegate control to and click OK.
7. Click OK again to close the OU properties window and apply the changes.
8. To remove a manager from an OU, follow the same steps but click Clear instead of
Change on the Managed By tab.
Using a command-line interface
To add a manager for an OU, use the following syntax:
> admod -b <ObjectDN> managedBy::<ManagerDN>
To clear the managedBy attribute, use the following:
> admod -b <ObjectDN> managedBy:-
Using PowerShell
You can use the following command to configure the Test OU to be managed by the
account with a CN of Administrator:
Set-ADOrganizationalUnit "ou=test,dc=adatum,dc=com" -ManagedBy "Administrator"
Or, you can also specify the DN in place of the CN as shown in the following example:
Set-ADOrganizationalUnit "ou=test88,dc=woodgrovebank,dc=com"↵
-ManagedBy "cn=aministrator,cn=users,dc=adatum,dc=com"
Discussion
In the case of an OU, specifying a user, group, computer, or another OU in the Managed
By tab does not confer any particular rights onto the manager; this is used as a strictly
informational field. When you configure a manager for an OU, the manager’s DN is
placed in the OU’s managedBy attribute, and the OU’s DN is placed in the manager’s
managedObjects attribute. managedObjects is the backlink attribute of managedBy,
showing all objects where that manager is specified.
See Also
MSDN: Managed-by attribute [AD Schema]; MSDN: Managed-Objects [AD Schema]
184 | Chapter 5: Organizational Units
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
210
|
5.14. Linking a GPO to an OU
Problem
You want to apply the settings in a GPO to the users and/or computers within an OU,
also known as linking the GPO to the OU.
Solution
Using a graphical user interface
1. Open the Group Policy Management snap-in (gpmc.msc).
2. Expand Forest in the left pane.
3. Expand Domains, expand the targeted domain name, and then navigate down to
the OU in the domain you want to link the GPO to.
4. Right-click on the OU and select either “Create a GPO in this domain, and Link it
here” (if the GPO does not already exist) or “Link an Existing GPO” (if you have
already created the GPO).
5. To unlink a GPO, right-click on an existing link and remove the checkmark next
to Link Enabled.
Using PowerShell
To link the "Marketing" Group Policy Object to the Marketing OU in adatum.com, use
the following PowerShell command:
New-GPLink -Name "Marketing" -Target "ou=marketing,dc=adatum,dc=com"
Discussion
The GPOs that are linked to an OU are stored in the gpLink attribute of the OU. The
format of the gpLink attribute is kind of strange, so you have to be careful when pro‐
grammatically or manually setting that attribute. Since multiple GPOs can be linked to
an OU, the gpLink attribute has to store multiple values; unfortunately, it does not store
them in a multivalued attribute as you might expect. Instead, the links are stored as part
of the single-valued gpLink attribute. The ADsPath of each linked GPO is concatenated
into a string, with each enclosed in square brackets. The ADsPath for each GPO is
followed by ;0 to signify the link is enabled or ;1 to signify the link is disabled. Here is
an example gpLink with two GPOs linked:
[LDAP://cn={6491389E-C302-418C-8D9DBB24E65E7507},cn=policies,cn=system,dc=adatum,dc=com;0]
5.14. Linking a GPO to an OU | 185
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
211
|
[LDAP://cn={6AC1786C-016F11D2-945F-00C04fB984F9},cn=policies,cn=system,dc=adatum,dc=com;0]
See Also
Recipe 9.14 for more information on the Group Policy Management snap-in
5.15. Protecting an OU Against Accidental Deletion
Problem
You want to prevent an organizational unit object from being accidentally deleted.
Solution
Using a graphical user interface
1. Open Active Directory Users and Computers (dsa.mc). Click on View and confirm
that Advanced Features is selected.
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 OU 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 <OU DN> /d EVERYONE:SDDT
Using PowerShell
Set-ADOrganizationalUnit -Identity "ou=test,dc=adatum,dc=com"↵
-ProtectedFromAccidentalDeletion:$True
Discussion
One of the challenges in delegating permissions within Active Directory is the potential
for accidental deletions, particularly when administrators delete an entire organiza‐
tional unit when they had only intended to delete a single object within that OU. Since
Windows Server 2008, a new option is exposed in the Active Directory Users and Com‐
puters and Active Directory Sites and Services MMCs that will prevent an object from
186 | Chapter 5: Organizational Units
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
212
|
being deleted by means of a “fat-finger” deletion. By default, all new OUs that are created
via the Active Directory Users and Computers MMC will have this protection enabled;
however, any preexisting OUs or OUs created through other methods will not unless
you enable it manually using one of the methods shown in this recipe. Additionally,
built-in Active Directory containers, such as the BUILTIN, Computers, and Users con‐
tainers, as well as the Domain Controllers OU and other built-in containers, do not have
this protection enabled by default. If you attempt to delete an OU that is protected using
this option, even when signed on as a Domain Admin or other similarly elevated ac‐
count, you will receive an “Access Denied” message until you manually remove the
checkbox or manually remove the deny ACE associated with it.
If you wish to enable this protection for all OUs that were present in your environment,
you can automate the use of dsacls with a for do loop, as follows:
for /f "tokens=*" %i in ('dsquery ou -limit 0') do dsacls %i /d everyone:SDDT
You can also automate the process through PowerShell by piping the results of a GetADOrganizationalUnit query into the Set-ADOrganizationalUnit cmdlet, as follows:
Get-ADOrganizationalUnit -Filter * |↵
Set-ADOrganizationalUnit -ProtectedFromAccidentalDeletion:$True
One advantage to using the command-line or PowerShell method is that this protection
can be applied to container and leaf objects in all versions of Windows Server, even
though the GUI checkbox is available only in Windows Server 2008 and later.
5.15. Protecting an OU Against Accidental Deletion | 187
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
213
| null |
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
214
|
CHAPTER 6
Users
6.0. Introduction
User accounts are some of the most frequently used objects in Active Directory; they
create the means of authenticating and authorizing someone to access resources on your
network. Because Windows server systems authenticate and authorize users primarily
through Active Directory, many key issues that system administrators deal with are
covered in this chapter. In particular, Active Directory manages information regarding
user passwords; group membership; enabling, disabling, or expiring user accounts; and
keeping track of when users have logged on to the network.
The Anatomy of a User
The default location for user objects in a domain is the cn=Users container directly off
the domain root. You can, of course, create user objects in other containers and or‐
ganizational units in a domain, or move them to these containers after they’ve been
created. Table 6-1 contains a list of some of the interesting attributes that are available
on user objects. This is by no means a complete list. There are many other informational
attributes that we haven’t included.
Table 6-1. Attributes of user objects
Attribute Description
accountExpires Large integer representing when the user’s account is going to expire. See Recipe 6.31
for more information.
cn Relative distinguished name of user objects. This is commonly the username or the
display name of the user.
displayName Typically the full name of a user. This attribute is used in administrative tools to
display a user’s descriptive name.
givenName First name of the user.
189
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
215
|
Attribute Description
homeDirectory Local or UNC path of user’s home directory. See Recipe 6.31 for more information.
homeDrive Defines the drive letter to map the user’s home directory to. See Recipe 6.31 for more
information.
lastLogon The last time that a user logged on to a particular DC. This information is not replicated
among domain controllers.
lastLogonTimestamp Approximate last logon timestamp, which is replicated among domain controllers.
See Recipe 6.37 for more information.
managedObjects Multivalued, linked attribute (with managedBy) that contains a list of DNs of objects
the user manages.
lockoutTime Large integer representation of the timestamp for when a user was locked out. See
Recipe 6.13 for more information.
memberOf Backlink listing of DNs of the groups the user is a member of. See Recipe 6.21 for more
information.
objectSid Octet string representing the SID of the user.
primaryGroupID ID of the primary group for the user. See Recipe 6.23 for more information.
profilePath UNC path to profile directory. See Recipe 6.31 for more information.
pwdLastSet Large integer denoting the last time the user’s password was set. See Recipe 6.27 for
more information.
sAMAccountName NetBIOS-style name of the user; limited to 20 characters to support legacy applications.
sIDHistory Multivalued attribute that contains a list of SIDs that are associated with the user.
scriptPath Path and filename of logon script. See Recipe 6.33 for more information.
sn Last name of user.
tokenGroups List of SIDs for the groups in the domain the user is a member of (both directly and
via nesting).
unicodePwd Octet string that contains a hash of a user’s password. This attribute cannot be directly
queried.
userAccountControl Account flags that define such things as account status and password change status.
userPrincipalName Internet-style account name for a user, which the user can use to log on to a computer.
In most cases this should map to the user’s email address, but this does not always
need to be the case.
userWorkstations List of computers a user can log on to, stored as a Unicode string.
msDS-PSOApplied New since Windows Server 2008. A backlink that lists the Password Settings Objects
that are applied to a user object.
msDS-ResultantPSO New since Windows Server 2008. A constructed attribute that indicates which PSO is
in effect for a user object.
msDSUserPasswordExpiryTimeCompu
ted
New since Windows Server 2008. A constructed attribute that indicates when a user’s
password is going to expire.
msDSFailedInteractiveLogonCount
New since Windows Server 2008. Indicates the number of failed interactive logons for
a user account since the Interactive Logon Count feature was enabled.
190 | Chapter 6: Users
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
216
|
Attribute Description
msDSFailedInteractiveLogonCoun
tAtLastSuccessfulLogon
New since Windows Server 2008. Indicates the number of failed interactive logons for
a user account since the last time the user successfully logged on interactively.
msDSLastFailedInteractiveLogon
Time
New since Windows Server 2008. Indicates the last time and date that the user
performed an unsuccessful interactive logon.
msDSLastSuccessfulInteractiveLo
gonTime
New since Windows Server 2008. Indicates the last time and date that the user
performed a successful interactive logon.
msDS-AuthenticatedAtDC New since Windows Server 2008. A multivalued attribute listing the RODCs through
which a user has successfully authenticated to a full DC.
msDS-RevealedDSAs New since Windows Server 2008. Backlink indicating which RODCs have cached a user’s
password secrets.
msDS-ManagedPassword New since Windows Server 2012. Contains password information for group-managed
service accounts.
6.1. Modifying the Default Display Name Used When
Creating Users in ADUC or ADAC
Problem
You want to modify how the default display name gets generated when you create a new
user through the ADUC snap-in or through the Active Directory Administrative Center.
Solution
Using a graphical user interface
1. Open ADSI Edit.
2. In the Configuration Naming Context, browse to DisplaySpecifiers→<Locale>
where <Locale> is the locale for your language (e.g., the U.S. English locale is 409).
3. Double-click on cn=user-Display.
4. Edit the createDialog attribute with the value you want the new default to be (e.g.,
%<sn>, %<givenName>).
5. Click OK.
Using a command-line interface
> admod -config -rb cn=user-Display,cn=409,cn=DisplaySpecifiers↵
createDialog::"%<sn>, %<givenName>"
6.1. Modifying the Default Display Name Used When Creating Users in ADUC or ADAC | 191
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
217
|
Using PowerShell
To modify display specifiers using PowerShell, run the following command:
Set-ADObject↵
-Identity "cn=user-Display,cn=409,cn=DisplaySpecifiers,cn=configuration,↵
dc=adatum,dc=com"; -Add @{createDialog="%<sn>, %<givenname>"}
Discussion
When you create a new user object in ADUC or ADAC, it will automatically fill in the
Full Name field as you type in the First Name, Initials, and Last Name fields. As a
convenience, you may want to alter that behavior so that it automatically fills in a dif‐
ferent value. To do that, you need to modify the User-Display display specifier, which
has the following distinguished name:
cn=user-Display,cn=<Locale>,cn=DisplaySpecifiers,cn=Configuration,<ForestRootDN>
<Locale> should be replaced with your language-specific locale, and <ForestRootDN>
should contain the distinguished name for your forest root domain. You need to modify
the createDialog attribute, which by default has no value. Replacement variables are
presented by %<attribute>, where attribute is an attribute name. For example, if you
wanted the default to be “LastName, FirstName”, you would use the following value:
%<sn>, %<givenName>
See Also
MS KB 250455 (XADM: How to Change Display Names of Active Directory Users)
6.2. Creating a User
Problem
You want to create a user object.
Solution
Using a graphical user interface
1. Open the Active Directory Administrative Center.
2. In the left pane, click to highlight the domain.
3. In the right pane, click New and then click User.
192 | Chapter 6: Users
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
218
|
4. The two required fields are Full Name and sAMAccountName. The Full Name field
will automatically be populated if you enter at least a first or a last name. Fill out
any of the remaining fields and then click OK to complete the new-user creation.
Using a command-line interface
You can create a user with the built-in DSAdd utility or by using AdMod. Use the fol‐
lowing DSAdd syntax:
> dsadd user "<UserDN>" -upn <UserUPN> -fn "<UserFirstName>"↵
-ln "<UserLastName>" -display "<UserDisplayName>" -pwd <UserPasswd>
To create a user account with AdMod, use the following syntax:
> admod -b "<UserDN>" -add objectClass::user sAMAccountName::<SAMAccount>
Using PowerShell
To create a new Active Directory user with PowerShell, use the following syntax:
New-ADUser -Name "<User CN>" -Path "<Parent DN>" -GivenName "<User First Name>"↵
-Surname "<User Last name>" -sAMAccountName "<User sAMAccountName>"
Discussion
To make a user account immediately available for a user, you’ll need to make sure the
account is enabled, which is accomplished by setting userAccountControl to 512 after
you’ve set a password that follows any password complexity rules in place for the user
(order is important in this case). If you set only the attributes shown in the commandline and PowerShell examples, then the user accounts will be disabled by default.
You can also create user accounts using the inetOrgPerson class, which is described in
Recipe 6.4. inetOrgPerson objects can be used for user authentication and restricting
access to resources in much the same way as user objects.
Using a graphical user interface
To set additional attributes, double-click on the user account after it has been created.
There are several tabs to choose from that contain attributes that are grouped together
based on function (e.g., Profile).
Using a command-line interface
Several additional attributes can be set with the dsadd user command. Run dsadd
user /? for the complete list. When creating a user with AdMod, you must specify the
objectClass and sAMAccount attributes at a minimum. You can add additional at‐
tributes with the admod command by using the <attributename>::<value> syntax.
6.2. Creating a User | 193
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
219
|
Using PowerShell
When using the New-ADUser cmdlet, there are about 50 common switches that can be
used. In addition, you can specify the –OtherAttributes switch to set less common
attributes. Here is a list of some of the common switches:
• -Name
• -AccountPassword
• -City
• -Company
• -Department
• -Description
• -DisplayName
• -GivenName
• -HomeDirectory
• -HomeDrive
• -Manager
• -OfficePhone
• -PostalCode
• -SamAccountName
• -State
• -StreetAddress
• -Surname
• -Title
See Also
Recipe 6.3 for creating users in bulk; Recipe 6.4 for creating an inetOrgPerson user;
Recipe 6.31; MSDN: ADS_USER_FLAG_ENUM
6.3. Creating a Large Number of Users
Problem
You want to create a large number of user objects, either for testing purposes or to
initially populate Active Directory with your employee, customer, or student user
accounts.
194 | Chapter 6: Users
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
220
|
Solution
Using a command-line interface
The following example uses a for do loop in combination with dsadd to create 1,000
users under the bulk OU in the adatum.com domain with usernames following the
naming convention of User1, User2, User3, etc. The password is set, but other attributes
are not configured. However, you can modify the dsadd command to populate addi‐
tional attributes, as well.
> for /L %i in (1,1,1000) do dsadd user "cn=User%i,ou=bulk,dc=adatum,dc=com"↵
-samid User%i -pwd N78ie.%i
You can also use the ldifde utility to perform a bulk import of unique usernames. Create
an .ldf file using the following syntax (separate multiple entries with a blank line in
between):
dn: cn=Joe Richards, ou=Engineering, dc=adatum, dc=com
changetype: add
cn: Joe Richards
objectClass: user
samAccountName: jrichards
Once you’ve created the LDIF file containing your user records, import the file using
the following command:
> ldifde -i -f <filename.ldf> -s <servername>
You may notice that the LDIF file does not specify the user’s password; this attribute
must be modified after the user object has been created.
You can also use admod to automate this task. The following code will create 4,000 users
named "TestUser_1", "TestUser_2", "TestUser_3", etc.:
> admod -sc adau:4000;MyPassword1!;cn=testuser,ou=testou,dc=adatum,dc=com
Using PowerShell
The following PowerShell example will create 1,000 users with the Name1, Name2,
Name3 naming convention.
$i=1
do {New-ADUser -Name User$i
$i++
} while ($i -le 1000)
Discussion
Using ADSI, PowerShell, and the command-line utilities, you can create hundreds and
even thousands of users far more easily and quickly than you would be able to do through
6.3. Creating a Large Number of Users | 195
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
221
|
a graphical user interface. You can also modify the examples to pull real data from a
data source, such as an employee database.
Using a command-line interface
The AdMod syntax makes use of the -adau shortcut, which will add X number of users
with Y as their starting password, so that "-adau:4000;MyPassword1" will create 4,000
users with a starting password of "MyPassword1". If the starting password is not speci‐
fied, a unique random complex password will be generated for each user.
Using PowerShell
The PowerShell example contains multiple lines. After the do command, PowerShell
will drop down to a >> prompt, which indicates that the command is not complete. After
entering the final line of the script, you need to press the Enter key twice to execute the
script. Once complete, the configured PowerShell prompt will return.
See Also
Recipe 6.2 for creating a user; MS KB 263911 (How to Set a User’s Password using
LDIFDE)
6.4. Creating an inetOrgPerson User
Problem
You want to create an inetOrgPerson object, which is the standard LDAP object class
to represent users.
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 Change Domain, enter the domain name, and click
OK.
3. In the left pane, browse to the parent container of the new user, right-click on it,
and select New→InetOrgPerson.
4. Enter text in the First Name, Last Name, and User Logon Name fields as appropriate
and click Next.
5. Enter and confirm the password, set any of the password flags, and click Next.
196 | Chapter 6: Users
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
222
|
6. Click Finish.
Using a command-line interface
DSAdd does not support creating inetOrgPerson objects, so use ldifde or AdMod in‐
stead. First, you need to create an LDIF file called create_inetorgperson.ldf with the
following contents:
dn: <UserDN>
changetype: add
objectclass: inetorgperson
sAMAccountName: <UserName>
dn: <UserDN>
changetype: modify
add: userAccountControl
userAccountControl: 512
Be sure to replace <UserDN> with the distinguished name of the user you want to add
and <UserName> with the user’s username. Then run the following command:
> ldifde -i -f create_inetorgperson.ldf
You can also use the admod utility to create an inetOrgPerson object, as follows:
> admod -b "cn=inetOrgPerson,cn=Users,dc=adatum,dc=com"↵
objectclass::inetOrgPerson sAMAccountName::inetOrgPerson -add
Using PowerShell
To create an inetOrgPerson object by using PowerShell, use the following syntax:
New-ADObject -Type inetOrgPerson -Name "<UserName>"↵
-Path "ou=users,dc=adatum,dc=com" -OtherAttributes↵
@{SamAccountName="<UserName>";UserPrincipalName="<UserUPN>"}
Discussion
The inetOrgPerson object class was defined in RFC 2798. It is the closest thing in the
LDAP world to a standard representation of a user, and most LDAP vendors support
the inetOrgPerson class. Unfortunately, Microsoft did not support inetOrgPersonwith
the initial release of Active Directory. Even though it provided an add-on later to extend
the schema to support it, the damage had been done. Most Active Directory imple‐
mentations were already using the user object class and were unlikely to convert, which
required vendors to build in support for the user class.
You can create inetOrgPerson objects for your users, who can use them to authenticate
just like accounts of the user object class. If you haven’t deployed Active Directory yet
and you plan to integrate a lot of third-party LDAP-based applications that rely on
inetOrgPerson, you may want to consider using it instead of the user class. You won’t
6.4. Creating an inetOrgPerson User | 197
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
223
|
be losing any information or functionality because the inetOrgPerson class inherits
directly from the user class. For this reason, the inetOrgPerson class has even more
attributes than the Microsoft user class.
The one potential downside is that some of the Microsoft tools, such as the DS utilities,
do not support modifying inetOrgPerson objects. (You can, however, use AdMod to
perform these modifications.)
See Also
Recipe 6.2 for creating a user; MS KB 314649; RFC 2798 (Definition of the InetOrg‐
Person LDAP Object Class)
6.5. Converting a user Object to an inetOrgPerson Object
(or Vice Versa)
Problem
You want to convert one or more user objects to inetOrgPerson objects to improve
interoperability in a heterogeneous environment.
Solution
Using a graphical user interface
1. Open ADSI Edit.
2. If an entry for the naming context you want to browse is not already displayed, do
the following:
a. Right-click on ADSI Edit in the right pane and click “Connect to.”
b. Fill in the information for the domain naming context, container, or OU that
contains the object you want to modify. Click the Advanced button if you need
to enter alternate credentials.
3. In the left pane, browse to the naming context, container, or OU containing the
user object that you want to view. Once you’ve found the object, right-click on it
and select Properties.
4. Scroll to objectClass and select Edit.
5. Under “Value to add,” enter inetOrgPerson and click Add.
6. Click OK twice to save your changes.
198 | Chapter 6: Users
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
224
|
Using a command-line interface
To convert a user object to an inetOrgPerson object, use the following syntax:
> admod -b "<UserDN>" objectClass:+:inetOrgPerson
To revert the object back to a regular user, replace + with - in the pre‐
vious syntax.
Using PowerShell
To convert a user object to an inetOrgPerson object, use the following syntax:
Set-ADObject -Identity "<UserDN>" -Add @{objectClass="inetOrgPerson"}
Discussion
In a heterogeneous environment, you may wish to convert one or more Active Directory
user objects to inetOrgPerson objects. Since the inetOrgPerson class inherits from the
user class, making this modification is a simple matter of adding the "inetOrgPer
son" value to an object’s objectClass attribute. It’s important to note that this is the
only instance in which you can modify structural classes in this manner; you can’t simply
modify a user object with whatever class you wish, even if that class inherits from the
user class.
You can easily modify the command-line and PowerShell solutions to convert all user
accounts in your domain (or just in a particular OU) to inetOrgPerson objects. For
example, the following combination of adfind and admod will search for all user ac‐
counts in the Marketing OU and convert each one to an inetOrgPerson object (the
-unsafe switch is necessary if you need to modify more than 10 objects at a time; you
can also use the -safety X switch and specify the actual number of objects that you
expect to modify for X):
adfind -default -rb "ou=Marketing" -f↵
"(&(objectcategory=person)(objectclass=User))" | admod↵
objectcategory:+:inetOrgPerson -unsafe
See Also
MS KB 307998 (Changing the Naming Attribute of the inetOrgPerson Class)
6.5. Converting a user Object to an inetOrgPerson Object (or Vice Versa) | 199
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
225
|
6.6. Modifying an Attribute for Several Users at Once
Problem
You want to modify an attribute for several users at once.
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 Change 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. Check the box beside the attribute(s) you want to modify and edit the fields for the
attributes.
6. Click OK.
Using a command-line interface
The following command sets the home directory of all users under a parent container
(<ParentDN>) to be on a particular fileserver (<FileServer>). The folder name is au‐
tomatically replaced with the sAMAccountName for the user by using the $username$
syntax:
> dsquery user "<ParentDN>" -limit 0 -scope onelevel | dsmod user -hmdir↵
"\\<FileServerName>\$username$"
Using PowerShell
Get-ADuser -SearchBase "<ParentDN>" -Filter * |↵
Set-ADUser -HomeDirectory "\\<FileServerName>\%username%"
Discussion
It is often necessary to update several users at once due to an organizational, geographic,
or fileserver change. In each solution, we showed how to modify all users within a parent
container, but you may need to use different criteria for locating the users.
200 | Chapter 6: Users
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
226
|
Within ADUC, it may appear that you are limited to modifying multiple users that reside
in the same container. However, you can create a saved query that returns users based
on any criteria you specify. You can then highlight those users and modify them as
described in the GUI solution.
With the CLI solution, you can modify the dsquery user command to search on what‐
ever criteria you want. The same applies in the PowerShell solution by using a filter or
an LDAP filter.
See Also
Recipe 4.8 for more information on searching AD
6.7. Deleting a User
Problem
You want to delete a user object.
Solution
Using a graphical user interface
1. Open the Active Directory Administrative Center.
2. In the right pane, enter the name of the user 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 user and then click Delete.
4. Click Yes to confirm the deletion, which will complete the deletion process.
Using a command-line interface
You can delete a user using the built-in dsrm utility, as well as AdMod. For dsrm, use
the following syntax:
> dsrm "<UserDN>"
For AdMod, enter the following:
> admod -b "<UserDN>" -del
Using PowerShell
To delete an object using PowerShell, use the following syntax:
Remove-ADUser -Identity "<UserDN>" -Confirm:$False
6.7. Deleting a User | 201
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
227
|
Discussion
This recipe covers deleting individual users. If you want to delete a container or OU
and all the objects in it, take a look at Recipe 4.25.
Using PowerShell
Using the –Confirm:$False parameter allows the deletion to occur without a confir‐
mation message from PowerShell.
See Also
Recipe 4.25 for deleting a container; MSDN:
IADsContainer::Delete; MSDN: IADsDeleteOps:: DeletesObject
6.8. Setting a User’s Profile Attributes
Problem
You want to set one or more of the user profile attributes.
Solution
Using a graphical user interface
1. Open the ADUC snap-in (dsa.msc).
2. In the left pane, right-click on the domain and select Find.
3. Select the appropriate domain beside In.
4. Beside Name, type the name of the user and click Find Now.
5. In the Search Results window, double-click on the user.
6. Click the Profile tab.
7. Modify the various profile settings as necessary.
8. Click OK.
Using a command-line interface
You can update a user’s profile attributes using either DSMod or AdMod. DSMod uses
the following syntax:
> dsmod user "<UserDN>" -loscr <ScriptPath> -profile <ProfilePath>↵
-hmdir <HomeDir> -hmdrv <DriveLetter>
AdMod uses the following syntax:
202 | Chapter 6: Users
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
228
|
> admod -b "<UserDN>" <attribute>::<NewValue>
Using PowerShell
To modify user profile attributes using PowerShell, use the following syntax:
Set-ADUser -Identity "<User DN>" -HomeDirectory "<HomeDir>"↵
-HomeDrive "<DriveLetter>" -ProfilePath "<ProfilePath>"↵
-ScriptPath "<ScriptPatch>"
Discussion
The four attributes that make up a user’s profile settings are:
homeDirectory
UNC path to home directory
homeDrive
Drive letter (e.g., Z:) to map home directory
profilePath
UNC path to profile directory
scriptPath
Path to logon script
When you set the homeDirectory attribute, the folder being referenced needs to already
exist. For an example on creating shares for users, see MS KB 234746.
See Also
Recipe 6.6 for methods to modify the attributes for multiple users
6.9. Moving a User
Problem
You want to move a user object to a different container or OU.
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 Change Domain, enter the domain name, and click
OK.
6.9. Moving a User | 203
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
229
|
3. In the left pane, right-click on the domain and select Find.
4. Type the name of the user and click Find Now.
5. In the Search Results window, right-click on the user and select Move.
6. Browse to and select the new parent container or OU.
7. Click OK.
You can also drag and drop objects from one container or OU into
another.
Using a command-line interface
You can move an object using either the built-in DSMove utility or AdMod. DSMove
takes the following syntax:
> dsmove "<UserDN>" -newparent "<NewParentDN>"
To move an object using AdMod, do the following:
> admod -b "<CurrentUserDN>" -move "<NewParentDN>"
Using PowerShell
To move a user with PowerShell, use the following syntax:
Move-ADObject -Identity "<UserDN>" -TargetPath "<NewParentDN>"
Discussion
Moving a user object between OUs in the same domain has no direct impact on the
actual user in terms of any security or distribution groups that the user is a member of.
The things to be cautious of when moving the user to a new OU are different security
settings, different GPOs, and the possibility of breaking applications that have the user’s
DN hardcoded into them.
See Also
Recipe 4.20 for moving objects between OUs
204 | Chapter 6: Users
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
230
|
6.10. Redirecting Users to an Alternative OU
Problem
You want to redirect all new users from the default location (cn=Users) into a different
location that you specify.
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. Accepted the default and bind as the currently logged on user or select the option
to bind with credentials and then enter the credentials.
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, type wellKnownObjects.
12. For Values, enter the following:
B:32:A9D1CA15768811D1ADED00C04FD8D5CD:cn=Users,<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:A9D1CA15768811D1ADED00C04FD8D5CD:<NewUsersParent>,<DomainDN>
where <NewUsersParent> is the new parent container for new computer objects
(e.g., "ou=Adatum Users").
15. Select Add for the Operation and click the Enter button.
6.10. Redirecting Users to an Alternative OU | 205
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
231
|
16. Click the Run button.
17. The result of the operations will be displayed in the right pane of the main LDP
window.
Using the command-line interface
To redirect the default OU that new users will be created into, use the following syntax:
> redirusr "<DestinationDN>"
Discussion
Most modern methods for creating user accounts, including the Active Directory Ad‐
ministrative Center, ADUC MMC snap-in, AdFind, and DSAdd, allow you to specify
which OU a new user should be created in. However, some utilities, such as net user
or the WinNT ADSI provider, still rely on a legacy API that will create a user only in its
default location until an administrator manually moves it to another OU. The default
location is the cn=Users container; this can create issues applying Group Policy to new
user objects since the Users container cannot have a GPO linked to it. To ensure that
all newly created users receive the necessary Group Policy settings as soon as they are
created, use the redirusr.exe utility to redirect all new users that are not otherwise placed
into a designated OU into the destination OU that you specify. You need to run this
utility only once per domain, and the destination OU needs to exist before you run the
utility.
See Also
“Redirect Users and Computers”
6.11. Renaming a User
Problem
You want to rename a user.
Solution
Using a graphical user interface
1. Open the ADUC snap-in (dsa.msc).
2. In the left pane, right-click on the domain and select Find.
3. Type the name of the user and click Find Now.
206 | Chapter 6: Users
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
232
|
4. In the Search Results window, right-click on the user and select Rename.
5. You can modify the Full Name, First Name, Last Name, Display Name, User Logon
Name, and User Logon Name (pre-Windows 2000) fields.
6. Click OK after you are done.
Using a command-line interface
The following command will rename the RDN of the user:
> dsmove "<UserDN>" -newname "<NewUserName>"
You can modify the UPN (-upn), first name (-fn), last name (-ln), and display name
(-display) using the dsmod user command. For example, the following command will
change the user’s UPN and last name:
> dsmod user "<UserDN>" -upn "<NewUserUPN>" -ln "<NewUserLastName>"
You can also rename a user by using AdMod with the following syntax:
> admod -b "<UserDN>" -rename "<NewUserName>"
Using PowerShell
To rename a user object using PowerShell, use the following syntax:
Rename-ADObject -Identity "<UserDN>" -NewName "<NewCN>"
Discussion
Renaming a user object can have a couple of different meanings in Active Directory.
In the generic object sense, renaming an object consists of changing the RDN for the
object to something else, as when cn=jsmith becomes cn=joe. Typically, though, you
need to rename more than that with users. For example, let’s say you had a username
naming convention of FirstInitialLastName, so Joe Smith’s username would be
jsmith. Let’s pretend that Joe decides one day that Smith is way too common and he
wants to be unique by changing his last name to Einstein. Now his username should
be jeinstein. The following attributes would need to change to complete a rename of
his object:
• His RDN should change from cn=jsmith to cn=jeinstein.
• His sAMAccountName should change to jeinstein.
• His userPrincipalName (UPN) should change to jeinstein@adatum.com.
• His mail (email address) attribute should change to jeinstein@adatum.com.
• His sn (last name) attribute should change to Einstein.
6.11. Renaming a User | 207
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
233
|
While this example may be contrived, it shows that renaming Joe Smith to Joe Einstein
can take up to five attribute changes in Active Directory, or more if you include updates
to proxy addresses and other attributes that are typically tied to the user’s name. It is
also important to note that if you change any of the first three in the bulleted list (RDN,
SAM Account Name, or UPN), you should have the user log off and log back on after
the changes have replicated. Since most applications and services rely on user GUID or
SID, which doesn’t change during a user rename, the person should not be affected, but
you want to have him log off and back on anyway, just in case.
See Also
Recipe 4.23 for renaming objects
6.12. Copying a User
Problem
You want to copy an existing user account, which may be serving as a template, to create
a new account.
Solution
Using a graphical user interface
1. Open the ADUC snap-in (dsa.msc).
2. In the left pane, browse to the parent container of the template user object.
3. In the right pane, right-click on the user and select Copy.
4. Enter the name information for the new user and click Next.
5. Enter a password, check any options you want enabled, and click Next.
6. Click Finish.
Using PowerShell
To create a new user from a template with PowerShell, use the following syntax:
$user = Get-ADUser -Identity <TemplateUserDN>↵
-Properties department, co, title, l, c, st, countrycode
New-ADUser -Instance $user -Name "<NewUserName>" -DisplayName↵
"<NewDisplayName>" -GivenName "<NewGivenname>" -Surname "<NewSuname>"↵
-UserPrincipalName "<NewUPN>" -SamAccountName "<NewSamAccountName>"↵
-PasswordNotRequired $true -Enable $true
208 | Chapter 6: Users
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
234
|
Discussion
Copying a user consists of copying the attributes that are common among a certain user
base, which can include department, address, and perhaps even organizational infor‐
mation. ADUC actually uses attributes that are marked in the schema as “Copied when
duplicating a user” to determine which attributes to copy. If you are interested in finding
the attributes that are configured in the schema to get copied, see Recipe 10.11.
Using a graphical user interface
To copy a user in ADUC, you have to browse to the user object. If you locate the user
by using Find instead, the Copy option is not available when right-clicking a user in the
Search Results window.
See Also
Recipe 10.11 for finding the attributes that should be copied when duplicating a user
6.13. Finding Locked-Out Users
Problem
You want to find users whose accounts are locked out.
Solution
Using a command-line interface
The following command finds all locked-out users in the domain of the specified do‐
main controller:
> unlock <DomainControllerName> * -view
Using PowerShell
The following command finds all locked-out users in the current domain:
Search-ADAccount -LockedOut -UsersOnly | FT Name,LockedOut -AutoSize
Discussion
Despite the deceptively simple commands just shown, finding the accounts that are
currently locked out is a surprisingly complicated task. You would imagine that you
could run a query using DSQuery or AdFind (similar to the one to find disabled users
in Recipe 6.20), but unfortunately, it is not that easy.
6.13. Finding Locked-Out Users | 209
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
235
|
The lockoutTime attribute is populated with a timestamp when a user is locked. One
way to find locked-out users would be to find all users that have something populated
in lockoutTime (i.e., lockoutTime=*). That query would definitely find all the currently
locked users, but it would also find all the users that subsequently became unlocked and
have yet to log in since being unlocked; the lockoutTime attribute doesn’t get reset until
the next time the user logs on successfully. This is where the complexity comes into play.
To determine the users that are currently locked out, you have to query the attribute
lockoutDuration stored on the domain object (e.g., dc=adatum,dc=com). This attribute
defines the number of minutes that an account will stay locked before becoming auto‐
matically unlocked. You need to take this value and subtract it from the current time to
derive a timestamp that would be the outer marker for which users could still be locked.
You can then compare this timestamp with the lockoutTime attribute of the user object.
The search filter to find all locked users once you’ve determined the locked timestamp
would look something like this:
(&(objectcategory=Person)(objectclass=user)(lockoutTime>DerivedTimestamp))
For any users that have a lockoutTime that is less than the derived timestamp, their
account has already been automatically unlocked per the lockoutDuration setting.
None of the current standard GUI or CLI tools incorporates this kind of logic, but
fortunately joe Richards wrote the unlock.exe utility, which does. And as its name im‐
plies, you can also unlock locked accounts with it. Thanks, joe!
See Also
“Details of Account Lockout Settings and Processes”
6.14. Unlocking a User
Problem
You want to unlock a locked-out user.
Solution
Using a graphical user interface
1. Open the ADUC snap-in (dsa.msc).
2. In the left pane, right-click on the domain and select Find.
3. Select the appropriate domain.
4. Type the name of the user and click Find Now.
5. In the Search Results window, right-click on the user and select Properties.
210 | Chapter 6: Users
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
236
|
6. Click the Account tab and then click Unlock account.
7. Click OK.
Using a command-line interface
To unlock all locked user accounts in your domain, use unlock.exe with the following
syntax:
> unlock . *
To unlock a specific user object, replace * with the user’s sAMAccountName or distin‐
guished name, as follows:
> unlock . joe.smith
Using PowerShell
Unlock-ADAccount -Identity <UserDN>
To unlock all locked user accounts in your domain, use the following syntax:
Search-ADAccount -LockedOut -UsersOnly | Unlock-ADAccount
Discussion
If you’ve enabled account lockouts for an Active Directory domain (see Recipe 6.13),
some users may eventually get locked out. A user can get locked out for a number of
reasons, but generally it is because a user mistypes her password a number of times,
changes her password and does not log off and log on again, or has services or scheduled
tasks running under the security context of her individual user account rather than a
service account.
You can use ADSI’s IADsUser::IsAccountLocked method to determine whether a user
is locked out. You can set IsAccountLocked to FALSE to unlock a user. You can also
query the msDS-User-Account-Control-Computed attribute of an object.
See Also
Recipe 6.13 for finding locked-out users; Recipe 6.15 for viewing the account lockout
policy; MSDN: Account Lockout
6.15. Troubleshooting Account Lockout Problems
Problem
A user is having account lockout problems and you need to determine from where and
how the account is getting locked out.
6.15. Troubleshooting Account Lockout Problems | 211
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
237
|
Solution
Using a graphical user interface
LockoutStatus is a program available for Windows that can help identify the domain
controller that handled the lockout. It works by querying the lockout status of a user
against all domain controllers in the user’s domain.
To determine the lockout status of a user:
1. Launch LockoutStatus and select File→Select Target from the menu.
2. Enter the target username and the domain of the user.
3. Click OK.
At this point, each domain controller in the domain will be queried and the results will
be displayed. To dive deeper and figure out which computer the lockout occurred on,
you need to use the EventCombMT utility and point it at the domain controller that
handled the lockout. EventCombMT can query the domain controller with the specific
lockout event IDs that will allow you to find the computer.
Discussion
The lockoutstatus.exe utility is just one of many that is available in the Account Lockout
and Management tool set provided by Microsoft. These lockout tools are intended to
help administrators with account lockout problems that were very difficult to trouble‐
shoot in the past. Along with the tool mentioned in “Solution”, here are a few others
that are included in the set:
ALockout.dll
A script that uses this DLL, called EnableKerbLog.vbs (included with the tool set),
can be used to enable logging of application authentication. This can help identify
applications that are using bad credentials and causing account lockouts.
ALoInfo.exe
This displays services and shares that are using a particular account name. It can
also print all the users and their password ages.
NLParse.exe
This is a filter tool for the netlogon.log files. You can use it to extract just the lines
that relate to account lockout information.
EventCombMT
This utility parses event logs from multiple servers, either to collect all entries to‐
gether or to search for individual events across multiple computers. This is
212 | Chapter 6: Users
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
238
|
extremely useful when troubleshooting user account lockouts, for example, by de‐
termining which computer is causing the account lockout.
All the Account Lockout tools are available for download from the Microsoft Download
Center.
See Also
Account Lockout Best Practices White Paper and Troubleshooting Account Lockout
the PSS Way
6.16. Viewing the Domain-Wide Account Lockout and
Password Policies
Problem
You want to view the domain-wide account lockout and password policies for a domain.
Solution
Using a graphical user interface
1. Open the Group Policy Management snap-in (gpmc.msc).
2. In the left pane, expand the forest, expand Domains, expand the desired domain,
expand Group Policy Objects, and then click the Default Domain Policy.
3. In the right pane, click the Settings tab to generate a report of all of the GPO settings.
4. Click “show” to the right of Security Settings and then click “show” to the right of
Accounts Policies/Password Policy to view the password policy.
5. Click “show” to the right of Account Policies/Account Lockout Policy to view the
account lockout policy.
Using PowerShell
To retrieve the minimum password length, number of passwords remembered, pass‐
word properties, and lockout threshold of the domain-wide password policy for the
adatum.com domain using PowerShell, run the following command:
Get-ADObject "dc=adatum,dc=com" -Properties * |↵
FL minPwdLength,pwdHistoryLength,pwdProperties,lockoutThreshold
To retrieve the maximum password age, minimum password age, lockout duration, and
lockout observation of the domain-wide password policy for the adatum.com domain
using PowerShell, use the following script:
6.16. Viewing the Domain-Wide Account Lockout and Password Policies | 213
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
239
|
$DOMAIN = Get-ADObject "dc=adatum,dc=com" -Properties *
$MAXPWDAGE = [System.TimeSpan]::FromTicks([System.Math]↵
::ABS($DOMAIN.maxPwdAge)).Days
$MINPWDAGE = [System.TimeSpan]::FromTicks([System.Math]↵
::ABS($DOMAIN.minPwdAge)).Days
$LOCKOUTDURATION =↵
; [System.TimeSpan]::FromTicks([System.Math]::ABS($DOMAIN.lockoutDuration)).Days
$LOCKOUTOBSERVATION =↵
; [System.TimeSpan]::FromTicks([System.Math]::↵
;ABS($DOMAIN.lockoutObservationWindow)).Days
Write-Host "Maximum password age:",↵
;$MAXPWDAGE;Write-Host "Minimum password age:",↵
;$MINPWDAGE;Write-Host "Lockout duration:",↵
;$LOCKOUTDURATION;Write-Host "Lockout observation:",$LOCKOUTOBSERVATION
Discussion
Several parameters controlling account lockout and password complexity can be set on
a domain-linked Group Policy Object such as the Default Domain Policy. The properties
that can be set for the password and account lockout policies include:
Account lockout duration
Number of minutes an account will be locked before being automatically unlocked.
A value of 0 indicates accounts will be locked out indefinitely—that is, until an
administrator manually unlocks them.
Account lockout threshold
Number of failed logon attempts after which an account will be locked.
Reset account lockout counter after
Number of minutes after a failed logon attempt that the failed logon counter for an
account will be reset to 0.
The properties that can be set for the Password Policy include:
Enforce password history
Number of passwords to remember before a user can reuse a previous password.
Maximum password age
Maximum number of days a password can be used before a user must change it.
Minimum password age
Minimum number of days a password must be used before it can be changed.
Minimum password length
Minimum number of characters a password must be.
214 | Chapter 6: Users
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
240
|
Password must meet complexity requirements
If enabled, passwords must meet all of the following criteria:
• Not contain all or part of the user’s account name
• Be at least six characters in length
• Contain characters from three of the following four categories:
a. English uppercase characters (A–Z)
b. English lowercase characters (a–z)
c. Base 10 digits (0–9)
d. Nonalphanumeric characters (e.g., !, $, #, %)
Store passwords using reversible encryption
If enabled, passwords are stored in such a way that they can be retrieved and de‐
crypted. This is essentially the same as storing passwords in plain text, and should
be avoided unless it is absolutely necessary.
In Windows Server 2003 and legacy versions of Windows, administrators can configure
only one password and account lockout policy for domain users, per domain. If a group
of users requires a different policy, a separate domain (and all of the hardware require‐
ments and administrative overhead associated with managing that separate domain) is
needed. Windows Server 2008 and later versions of Windows allow for the creation of
Fine-Grained Password Policies (FGPPs), which allow you to configure multiple pass‐
word policies within a single domain.
Using a graphical user interface
On a domain controller or any computer that has the Remote Server Administration
Tools (RSAT) installed, the Group Policy Management snap-in is available from the
Start menu under Administrative Tools.
Using PowerShell
In the first example, the pwdProperties attribute returns a value that indicates some of
the general settings of the password policy. For example, a 1 indicates that password
complexity is enabled. A 0 indicates that password complexity is disabled. The number
16 indicates that passwords are stored using reversible encryption.
In the second example, we have to deal with conversion from 100-nanosecond intervals,
which is how the values are stored.
See Also
“Account Lockout Best Practices White Paper”; MSDN: DOMAIN_PASSWORD_IN‐
FORMATION; “Pwd–Properties attribute (Windows)”
6.16. Viewing the Domain-Wide Account Lockout and Password Policies | 215
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
241
|
6.17. Applying a Fine-Grained Password Policy to a
User Object
Problem
You want to apply a Fine-Grained Password Policy (FGPP) to a user object.
Solution
Using a graphical user interface (steps specific to Windows Server 2012)
1. Open Active Directory Administrative Center.
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 user object 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 'cn=joer' user to the list of groups that a PSO will apply to:
psomgr -applyto cn=joer,cn=Users,dc=ADATUM,dc=COM -pso TestPSO -forreal
Using PowerShell
To ensure that a user will be a target of an FGPP, use the following syntax:
Add-ADFineGrainedPasswordPolicySubject -Identity "<Name of FGPP>"↵
-Subjects "<User Object sAMAccountName>"
Discussion
Once an FGPP has been created, you can modify the password and account lockout
settings controlled by the object, as well as the users and groups that it should apply to.
Since the PasswordSettingsObject is an Active Directory object class, these modifi‐
cations can be made using any interface that can modify objects. When working from
the command line, the psomgr tool from joeware allows you to modify one or multiple
PSOs at a time, and can also create “starter” PSOs using the -quickstart command-line
216 | Chapter 6: Users
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
242
|
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
Chapter 9
6.18. Viewing the Fine-Grained Password Policy That Is in
Effect for a User Account
Problem
You want to determine which FGPP is in effect for a particular user.
Solution
Using a graphical user interface
1. Open Active Directory Users and Computers. Click 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 the msDS-PSOApplied attribute. If an FGPP is applied directly to the user,
it will be shown in the value.
5. Scroll to the msDS-ResultantPSO attribute. If an FGPP is applied to a group that
the user is a member of, it will be shown in the value.
6. Click OK.
Using a command prompt
psomgr.exe -effective <User DN>
Using PowerShell
Get-ADObject -Identity "<UserDN>" -Properties "msDS-PSOApplied",↵
"msDS-ResultantPSO" | FL Name,msDS-PSOApplied,msDS-ResultantPSO
6.18. Viewing the Fine-Grained Password Policy That Is in Effect for a User Account | 217
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
243
|
Discussion
Within a domain, each user object contains a constructed backlink attribute called
msDS-ResultantPSO that indicates which PasswordSettingsObject 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, this PSO 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 6.18; Recipe 9.29
6.19. Enabling and Disabling a User
Problem
You want to enable or disable a user account.
Solution
Using a graphical user interface
1. Open the ADUC snap-in (dsa.msc).
2. In the left pane, right-click on the domain and select Find.
3. Select the appropriate domain.
4. Type the name of the user beside Name and click Find Now.
5. In the Search Results window, right-click on the user and select Enable Account to
enable, or Disable Account to disable.
218 | Chapter 6: Users
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
244
|
6. Click OK.
Using a command-line interface
To enable a user, use the following command:
> dsmod user "<UserDN>" -disabled no
To disable a user, use the following command:
> dsmod user "<UserDN>" -disabled yes
Using PowerShell
To use PowerShell to enable or disable a user account, use the following syntax:
Set-ADUser "<User DN>" -Enabled $False
Set-ADUser "<User DN>" -Enabled $True
Discussion
Account status is used to control whether a user is allowed to log on or not. When an
account is disabled, the user is not allowed to log on to his workstation with the account
or to access AD controlled resources. Much like the lockout status, the account status
is stored as a flag in the userAccountControl attribute (see Recipe 6.31).
There is an IADsUser::AccountDisabled property that allows you to determine and
change the status. Set the method to FALSE to enable the account or to TRUE to
disable it.
See Also
Recipe 6.20 for finding disabled users; Recipe 6.31 for more on the attribute
userAccountControl
6.20. Finding Disabled Users
Problem
You want to find disabled users in a domain.
Solution
Using a graphical user interface
1. Open the ADUC snap-in (dsa.msc).
2. In the left pane, connect to the domain you want to query.
6.20. Finding Disabled Users | 219
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
245
|
3. Right-click on the domain and select Find.
4. In the Find dropdown box, select Common Queries.
5. Click the “Disabled accounts” option box.
6. Click the Find Now button.
Using a command-line interface
You can enumerate all disabled user objects in your domain by using the built-in
DSQuery utility, as follows:
> dsquery user <DomainDN> -disabled
You can also use a bitwise query in AdFind to produce the same output, using the
following syntax:
> adfind -bit -b <DomainDN> -f↵
"&(objectcategory=person)(objectclass=user)(useraccountcontrol:AND:=2)"
You can replace <DomainDN> with the DN of a specific organizational
unit if you wish to restrict the results of your AdFind query.
Using PowerShell
To locate all disabled users in a domain by using PowerShell, run the following
command:
Get-ADUser -Filter {Enabled -eq "False"} | FL Name
Discussion
Users in Active Directory can be either enabled or disabled. A disabled user cannot log
in to the domain. Unlike account lockout, which is an automatic process that is based
on the number of times a user incorrectly enters a password, an account has to be
manually enabled or disabled.
All disabled user accounts have the bit that represents 2 (0010 base 2) set in their
userAccountControl attribute. This doesn’t mean that the attribute will be equal to 2,
it just means that the bit that equals 2 will be enabled—other bits may also be set. See
Recipe 4.12 and Recipe 4.15 for a more detailed explanation of bit flags.
See Also
Recipe 4.12; Recipe 4.15; Recipe 6.19 for enabling and disabling users
220 | Chapter 6: Users
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
246
|
6.21. Viewing a User’s Group Membership
Problem
You want to view the group membership of a user.
Solution
Using a graphical user interface
1. Open the ADUC snap-in (dsa.msc).
2. In the left pane, right-click on the domain and select Find.
3. Select the appropriate domain.
4. Type the name of the user beside Name and click Find Now.
5. In the Search Results window, double-click on the user.
6. Click the Member Of tab.
7. To view all indirect group membership (from nested groups), you’ll need to doubleclick on each group.
Using a command-line interface
The following command displays the groups that <UserDN> is a member of. Use the
-expand switch to list nested group membership as well:
> dsget user <UserDN> -memberof [-expand]
You can also use the GetUserInfo tool with the following syntax:
> getuserinfo \\<Domain>\<Username>
A third option would be to use the whoami tool, as follows:
> whoami /groups
To round out the command-line options for viewing group memberships, you can use
the MemberOf joeware utility with the following syntax:
> memberof -u <Domain>\<User>
To query group membership from a specific domain controller using
MemberOf, use the -s switch followed by the name of the DC.
6.21. Viewing a User’s Group Membership | 221
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
247
|
Using PowerShell
Get-ADUser "<User DN>" -Properties MemberOf | select -ExpandProperty MemberOf
Discussion
The memberOf attribute on user objects is multivalued and contains the list of distin‐
guished names for groups of which the user is a member. memberOf is actually linked
with the member attribute on group objects, which holds the distinguished names of its
members. For this reason, you cannot directly modify the memberOf attribute; you must
instead modify the member attribute on the group.
The primary group of a user, which the user is technically a member of, will not be
shown in the CLI or solutions except in the case of the MemberOf utility. This is due to
the fact that the primary group is not stored in the memberOf attribute like the rest of
the groups. See Recipes 6.23 and 7.11 for more on finding the primary group of a user.
Using PowerShell
The example command will display only the direct members of a group.
See Also
Recipe 6.23; Recipe 7.4 for more on viewing the nested members of a group; Recipe 7.11;
Recipe 10.15 for more information on linked attributes
6.22. Removing All Group Memberships from a User
Problem
You want to remove all group membership information from a user object.
Solution
Using a graphical user interface
1. Open the ADUC snap-in (dsa.msc).
2. In the left pane, right-click on the domain and select Find.
3. Select the appropriate domain.
4. Type the name of the user beside Name and click Find Now.
5. In the Search Results window, double-click on the user.
6. Click the Member Of tab.
222 | Chapter 6: Users
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
248
|
7. Highlight all groups listed in the Member Of tab and select Remove. Click Yes to
confirm.
8. Click OK.
Using a command-line interface
You can accomplish this task at the command line using a combination of AdFind and
AdMod:
> adfind -b <DomainDN> -f member=<UserDN> -dsq | admod member:-:<UserDN> -unsafe
Using PowerShell
To remove group memberships using PowerShell, use the following syntax:
Get-ADGroup -Filter {Name -ne "Domain Users"} |↵
ForEach-Object {Remove-ADGroupMember $_ -Members "<User DN>" -Confirm:$False}
Discussion
Using PowerShell
The example command filters out the Domain Users group. By default, the Domain
Users group is the primary group for user objects. You can’t remove a user from her
primary group. In some cases, a different group may be the primary group and, in such
situations, should be substituted for Domain Users in the command.
See Also
MSDN: Adding Members to Groups in a Domain [Active Directory]; MSDN: Group
Objects [Active Directory]
6.23. Changing a User’s Primary Group
Problem
You want to change the primary group of a user.
Solution
Using a graphical user interface
1. Open the ADUC snap-in (dsa.msc).
2. In the left pane, right-click on the domain and select Find.
6.23. Changing a User’s Primary Group | 223
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
249
|
3. Select the appropriate domain.
4. Type the name of the user beside Name and click Find Now.
5. In the Search Results window, double-click on the user.
6. Click the Member Of tab.
7. Click on the name of the group you want to set as the primary group.
8. Click the Set Primary Group button.
9. Click OK.
Using PowerShell
First, obtain the primarygroupToken of the desired primary group by using the follow‐
ing syntax:
Get-ADGroup -Identity "<GroupDN>" -Properties primarygroupToken |↵
FL primarygroupToken
Next, use the following syntax to replace the primaryGroupID attribute on a user back
to the Domain Users group (change the ID to the desired group ID based on the first
PowerShell command if the goal is to change the primary group to something else):
Set-ADObject "<UserDN>" -Replace @{PrimaryGroupID="513"}
Discussion
The primary group is a holdover from Windows NT that was used to support Macintosh
and POSIX clients. That being said, you might have some legacy applications that de‐
pend on the primary group, and therefore you may have to change some users’ primary
groups.
Changing the primary group is not difficult, but it is not straightforward, either. The
primary group is stored on user objects in the primaryGroupID attribute, which con‐
tains the RID of the primary group. You can obtain this value by querying the primary
GroupToken attribute on the target group object. Before you can set the primaryGrou
pID on the user object, you have to first make sure the user is a member of the group.
If you try to set the primaryGroupID for a group in which the user is not a member, you
will get an error.
The default primaryGroupID is set to 513 (Domain Users) for all users.
See Also
Recipe 7.11 for determining the group name given a group ID; MS KB 297951 (How to
Use the PrimaryGroupID Attribute to Find the Primary Group for a User)
224 | Chapter 6: Users
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
250
|
6.24. Copying a User’s Group Membership to Another User
Problem
You want to copy one user’s group membership to another user.
Solution
Using a graphical user interface
1. Open the ADUC snap-in (dsa.msc).
2. In the left pane, right-click on the domain and select Find.
3. Select the appropriate domain.
4. Beside Name, type the name of the user you want to transfer groups from and click
Find Now.
5. In the Search Results window, double-click on the user.
6. Click the Member Of tab.
7. For each group you want to add another user in, do the following:
a. Double-click on the group.
b. Click the Members tab.
c. Click the Add button.
d. Find the user you want to add in the object picker and click OK.
e. Click OK.
Using a command-line interface
The following command line will add <NewUserDN> to all of the groups that <CurrentU
serDN> is a member of:
> for /F "usebackq delims=""" %i in ('dsget user↵
"<CurrentUserDN>" -memberof') do dsmod group %i -addmbr "<NewUserDN>"
If you want to get fancy and remove <CurrentUserDN> from each of the groups in the
same operation, simply add an -rmmbr option on the end:
> for /F "usebackq delims=""" %i in ('dsget user↵
"<CurrentUserDN>" -memberof') do dsmod group %i -addmbr "<NewUserDN>"↵
-rmmbr "<CurrentUserDN>"
You can also add <NewUserDN> to all of the groups that <CurrentUserDN> is a member
of by using a combination of AdFind and AdMod, as follows:
6.24. Copying a User’s Group Membership to Another User | 225
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
251
|
> adfind -b <DomainDN> -f member=<Source User DN> -dsq |↵
admod member:+:<Dest. UserDN> -unsafe
Using PowerShell
To copy group memberships using PowerShell, use the following syntax:
$SOURCE=Get-ADUser -Identity "<SourceUserDN>" -Properties *
$DESTINATION="<DestinationUserDN>"
foreach ($group in $SOURCE.MemberOf)
{
Add-ADGroupMember -Identity $group -Members $destination
}
Discussion
Employees come and go; people take on new responsibilities and move on to new jobs.
It is common to have movement within an organization. When this happens, typically
someone is replacing the person who is moving on. The administrator needs to get the
new person up to speed as quickly as possible, including setting up accounts and grant‐
ing access to any necessary resources. A big part of this process includes adding the new
user to the correct groups. You can help facilitate this by using one of the processes
outlined in the “Solution” section to help the user gain access to the exact same groups
that the former employee was a member of.
One important issue to point out is that the memberOf attribute, which was used in the
command-line solutions to determine a user’s group membership, contains only the
groups that are visible to the DC that’s being queried; this can vary depending on
whether the DC in question is a global catalog and whether the user belongs to any
universal groups. Any groups the user is a member of outside of the user’s domain will
not be transferred. To transfer universal group membership outside of a domain, you
will need to perform a query against the global catalog for all group objects that have a
member attribute that contains the DN of the user. You can also search the global catalog
for the memberOf attribute for a given user to determine a user’s universal group
memberships.
See Also
Recipe 7.5 for adding and removing members of a group
6.25. Setting a User’s Password
Problem
You want to set the password for a user.
226 | Chapter 6: Users
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
252
|
Solution
Using a graphical user interface
1. Open the ADUC snap-in (dsa.msc).
2. In the left pane, right-click on the domain and select Find.
3. Select the appropriate domain.
4. Type the name of the user beside Name and click Find Now.
5. In the Search Results window, right-click on the user and select Reset Password.
6. Enter and confirm the new password.
7. Click OK.
Using a command-line interface
This command changes the password for the user specified by <UserDN>. Using * after
the -pwd option prompts you for the new password. You can replace *with the password
you want to set, but it is not a good security practice since other users that are logged
in to the machine may be able to see it:
> dsmod user <UserDN> -pwd *
You can modify the unicodepwd attribute directly by encrypting the admod connection
using the -kerbenc switch:
> admod -b "<UserDN>" unicodepwd::<Password> -kerbenc
You can also use admod with the #setpwd# switch:
> admod -b "<UserDN>" #setpwd#::<NewPassword>
Using PowerShell
To set a user’s password with PowerShell, use the following syntax:
$newPassword = (Read-Host -Prompt "Provide New Password" -AsSecureString)
Set-ADAccountPassword -Identity <UserDN> -NewPassword $newPassword -Reset
Discussion
The PowerShell solution follows the command-line solution model, which prompts for
the password instead of entering the password in plain text in the command. PowerShell
supports converting a plain text string as part of the command, but that method isn’t
considered as secure. You can use a plain text password in the password reset by using
the ConvertTo-SecureString -AsPlainText "<NewPassword>" option in place of the
password prompt. The following example shows the full command:
6.25. Setting a User’s Password | 227
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
253
|
Set-ADAccountPassword -Identity "<UserDN>" -Reset↵
-NewPassword (ConvertTo-SecureString -AsPlainText "<NewPassword>" -Force)
See Also
MS KB 225511 (New Password Change and Conflict Resolution Functionality in Win‐
dows); MSDN: IADsUser::SetPassword; MSDN: IADsUser::Change-Password
6.26. Preventing a User from Changing a Password
Problem
You want to disable a user’s ability to change his password.
Solution
Using a graphical user interface
1. Open the ADUC snap-in (dsa.msc).
2. In the left pane, right-click on the domain and select Find.
3. Select the appropriate domain.
4. Beside Name, type the name of the user you want to modify and click Find Now.
5. In the Search Results window, double-click on the user.
6. Click the Account tab.
7. Under Account options, check the box beside “User cannot change password.”
8. Click OK.
Using a command-line interface
> dsmod user <UserDN> -canchpwd no
Using PowerShell
> Set-ADAccountControl -Identity "<UserDN>" -CannotChangePassword $True
Discussion
Using a graphical user interface
Even though in the GUI solution you check and uncheck the “User cannot change
password” setting, actually making the change in Active Directory is a little more com‐
plicated. Not allowing a user to change his password consists of setting two deny Change
228 | Chapter 6: Users
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
254
|
Password ACEs on the target user object. One deny ACE is for the Everyone account
and the other is for Self.
To perform this change across multiple users, you can multiselect users in Active Di‐
rectory Users and Computers and then perform the remaining steps in the GUI solution.
See Also
“How to use the UserAccountControl flags to manipulate user account properties”
6.27. Requiring a User to Change a Password at
Next Logon
Problem
You want to require a user to change her password the next time she logs on to the
domain.
Solution
Using a graphical user interface
1. Open the ADUC snap-in (dsa.msc).
2. In the left pane, right-click on the domain and select Find.
3. Select the appropriate domain.
4. Beside Name, type the name of the user you want to modify and click Find Now.
5. In the Search Results window, double-click on the user.
6. Click the Account tab.
7. Under Account options, check the box beside “User must change password at next
logon.”
8. Click OK.
Using a command-line interface
You can configure the “User must change password” setting using either DSMod or
AdMod. To modify this setting using DSMod, use the following syntax:
> dsmod user "<UserDN>" -mustchpwd yes
For AdMod, do the following:
> admod -b "<UserDN>" pwdLastSet::0
6.27. Requiring a User to Change a Password at Next Logon | 229
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
255
|
Using PowerShell
To flag a user’s password to change on next logon with PowerShell, use the following
syntax:
Set-ADUser -Identity <UserDN> -ChangePasswordAtLogon $True
Discussion
Be careful when forcing users to change their password at next logon by using the
PowerShell solution. Active Directory Users and Computers will not allow you to force
a user to change her password at next logon if the user is already configured not to be
able to change her password. However, you can set both of those options by using
PowerShell. In such a situation, the user would not be able to log on.
6.28. Preventing a User’s Password from Expiring
Problem
You want to prevent a user’s password from expiring.
Solution
Using a graphical user interface
1. Open the ADUC snap-in (dsa.msc).
2. In the left pane, right-click on the domain and select Find.
3. Select the appropriate domain.
4. Beside Name, type the name of the user you want to modify and click Find Now.
5. In the Search Results window, double-click on the user.
6. Click the Account tab.
7. Under Account options, check the box beside “Password never expires.”
8. Click OK.
Using a command-line interface
> dsmod user "<UserDN>" -pwdneverexpires yes
Using PowerShell
To prevent a user’s password from expiring with PowerShell, use the following syntax:
Set-ADUser -Identity "<UserDN>" -PasswordNeverExpires $True
230 | Chapter 6: Users
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
256
|
Discussion
Setting a user’s password to never expire overrides any password-aging policy you’ve
defined in the domain. To disable password expiration, you need to set the bit equivalent
of 65,536 (i.e., 10000000000000000) in the userAccountControl attribute of the target
user.
See Also
Recipe 4.15 for more on modifying a bit flag attribute; Recipe 6.31 for more on setting
the userAccountControl attribute
6.29. Finding Users Whose Passwords Are About to Expire
Problem
You want to find the users whose passwords are about to expire.
Solution
Using a command-line interface
> dsquery user -stalepwd <NumDaysSinceLastPwdChange>
You can also use the FindExpAcc joeware tool with the following syntax:
> findexpacc -pwd -days <NumDaysUntilExpiration>
Using PowerShell
The following script finds users whose passwords will expire within seven days:
$Policy = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge.days
$DaysUntil = 7
Get-ADUser -Filter {(Enabled -eq "True") -and (PasswordNeverExpires↵
-eq "False")} -Properties * | Select Name,@{Name="Expires";↵
Expression={$Policy - ((Get-Date) - ($_.PasswordLastSet)).days}} |↵
Where-Object {$_.Expires -gt 0 -AND $_.Expires -le $DaysUntil}
Discussion
When a Windows-based client logs on to Active Directory, a check is done against the
effective password policy and the user’s pwdLastSet attribute to determine whether the
user’s password has expired. If it has, the user is prompted to change it. In a pure
Windows-based environment, this notification process may be adequate, but if you have
a lot of non-Windows-based computers that are joined to an Active Directory domain
(e.g., Kerberos-enabled Unix clients), or you have a lot of application and service
6.29. Finding Users Whose Passwords Are About to Expire | 231
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
257
|
accounts, you’ll need to develop your own user password expiration notification pro‐
cess. Even in a pure Windows environment, cached logins present a problem because
when a user logs in to the domain with cached credentials (i.e., when the client is not
able to reach a domain controller), this password expiration notification check is not
done.
The process of finding users whose passwords are about to expire is a little complicated.
Fortunately, the dsquery user command helps by providing an option for searching
for users that haven’t changed their password for a number of days (-stalepwd). The
downside to the dsquery user command is that it will find users whose passwords are
about to expire, users who are configured so that their passwords never expire, and users
that must change their passwords at next logon (i.e., pwdLastSet = 0).
Using a command-line interface
You can use the FindExpAcc tool to query Active Directory for expired user or computer
accounts, as well as active accounts with expired passwords. It also includes switches
that are familiar from AdFind and AdMod, such as -b to specify the Base DN, -f to
specify an LDAP filter, and so on.
The findexpacc utility can also be used to query for user accounts that are about to expire,
in addition to accounts with expiring passwords.
See Also
Recipe 6.16 for more on the password policy for a domain; Recipe 6.20; Recipe 6.25 for
how to set a user’s password; Recipe 6.28 for how to set a user’s password to never expire
6.30. Viewing the RODCs That Have Cached a
User’s Password
Problem
You wish to view the RODCs that have cached a user account’s password secrets.
Solution
Using a graphical user interface
1. Open ADSI Edit and connect to the default naming context.
2. In the left pane, navigate to the container or the OU that contains the user object.
3. In the right pane, right-click the user and click Properties.
4. Scroll down the list of attributes until you find the msDS-RevealedDSAs attribute.
232 | Chapter 6: Users
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
258
|
5. View the value of msDS-RevealedDSAs to view the RODCs that have cached the
user’s password.
6. Click OK or Cancel to close the Properties window.
Using a command-line interface
> adfind -b <UserDN> msDS-RevealedDSAs
Using PowerShell
> Get-ADUser -Identity "<UserDN>" -Properties "msDS-RevealedDSAs" |↵
FL msDS-RevealedDSAs
Discussion
Read-Only Domain Controllers (RODCs) improve the security of branch offices and
other remote environments. One of the security measures introduced by the RODC is
the Password Replication Policy (PRP), which specifies a list of users 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 ac‐
counts for whom each RODC has cached password secrets. Each user account, in turn,
maintains a backlink called msDS-RevealedDSAs. This backlink can be queried to de‐
termine 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
6.31. Setting a User’s Account Options
(userAccountControl)
Problem
You want to view or update the userAccountControl attribute for a user. This attribute
controls various account options, such as whether the user must change her password
at next logon and whether the account is disabled.
Solution
Using a graphical user interface
1. Open the ADUC snap-in (dsa.msc).
6.31. Setting a User’s Account Options (userAccountControl) | 233
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
259
|
2. In the left pane, right-click on the domain and select Find.
3. Select the appropriate domain.
4. Beside Name, type the name of the user and click Find Now.
5. In the Search Results window, double-click on the user.
6. Select the Account tab.
7. Many of the userAccountControl flags can be set under Account options.
8. Click OK when you’re done.
Using a command-line interface
The dsmod user command has several options for setting various userAccountCon
trol flags, as shown in Table 6-2. Each switch accepts yes or no as a parameter to either
enable or disable the setting.
Table 6-2. dsmod user options for setting userAccountControl
dsmod user switch Description
-mustchpwd Sets whether the user must change his password at next logon.
-canchpwd Sets whether the user can change his password.
-disabled Sets account status to enabled or disabled.
-reversiblepwd Sets whether the user’s password is stored using reversible encryption.
-pwdneverexpires Sets whether the user’s password never expires.
Using PowerShell
To modify user properties associated with the userAccountControl attribute, you have
several switches available through the set-ADUser cmdlet, including the following:
Set-ADUser -Identity <UserDN> -PasswordNeverExpires
Set-ADUser -Identity <UserDN> -ChangePasswordAtLogon
Set-ADUser -Identity <UserDN> -Enabled
To see all of the available properties that can be modified, run the following command:
Get-Command Set-ADUser -Syntax
Discussion
The userAccountControl attribute on user (and computer) objects could be considered
the kitchen sink of miscellaneous and sometimes completely unrelated user account
properties. If you have to work with creating and managing user objects very much,
you’ll need to become intimately familiar with this attribute.
234 | Chapter 6: Users
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
260
|
The userAccountControl attribute is a bit flag, which means you have to take a couple
of extra steps to search against it or modify it. See Recipe 4.12 for more on searching
with a bitwise filter and Recipe 4.15 for modifying a bit flag attribute.
The dsmod user command can be used to modify a subset of userAccountControl
properties, as shown in Table 6-2, and Table 6-3 contains the complete list of userAc
countControl properties as defined in the ADS_USER_FLAG_ENUM enumeration.
Table 6-3. ADS_USER_FLAG_ENUM values
Name Value Description
ADS_UF_SCRIPT 1 Logon script is executed.
ADS_UF_ACCOUNTDISABLE 2 Account is disabled.
ADS_UF_HOMEDIR_REQUIRED 8 View-only attribute. Indicates that Home Directory is
required.
ADS_UF_LOCKOUT 16 Account is locked out.
ADS_UF_PASSWD_NOTREQD 32 A password is not required.
ADS_UF_PASSWD_CANT_CHANGE 64 Read-only flag that indicates if the user cannot change
her password.
ADS_UF_ENCRYPTED_TEXT_PASSWORD_AL
LOWED
128 Store password using reversible encryption.
ADS_UF_NORMAL_ACCOUNT 512 Enabled user account.
ADS_UF_INTERDOMAIN_TRUST_ ACCOUNT 2048 A permit to trust account for a system domain that trusts
other domains.
ADS_UF_WORKSTATION_TRUST_ACCOUNT 4096 Enabled computer account.
ADS_UF_SERVER_TRUST_ACCOUNT 8192 Computer account for backup domain controller.
ADS_UF_DONT_EXPIRE_PASSWD 65536 Password will not expire.
ADS_UF_MNS_LOGON_ACCOUNT 131072 MNS logon account.
ADS_UF_SMARTCARD_REQUIRED 262144 Smart card is required for logon.
ADS_UF_TRUSTED_FOR_DELEGATION 524288 Allow Kerberos delegation.
ADS_UF_NOT_DELEGATED 1048576 Do not allow Kerberos delegation even if
ADS_UF_TRUSTED_FOR_DELEGATION is
enabled.
ADS_UF_USE_DES_KEY_ONLY 2097152 Requires DES encryption for keys.
ADS_UF_DONT_REQUIRE_PREAUTH 4194304 Account does not require Kerberos preauthentication
for logon.
ADS_UF_PASSWORD_EXPIRED 8388608 Read-only flag indicating account’s password has
expired. Only used with the WinNT provider.
ADS_UF_TRUSTED_TO_AUTHENTI
CATE_FOR_DELEGATION
16777216 Account is enabled for delegation.
ADS_UF_PARTIAL_SECRETS_ACCOUNT 67108864 Account is an RODC.
6.31. Setting a User’s Account Options (userAccountControl) | 235
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
261
|
See Also
Recipe 4.12; Recipe 4.15 for setting a bit flag attribute; “How to use the UserAccount‐
Control flags to manipulate user account properties”
6.32. Setting a User’s Account to Expire
Problem
You want a user’s account to expire at some point in the future.
Solution
Using a graphical user interface
1. Open the ADUC snap-in (dsa.msc).
2. In the left pane, right-click on the domain and select Find.
3. Select the appropriate domain.
4. Beside Name, type the name of the user you want to modify and click Find Now.
5. In the Search Results window, double-click on the user.
6. Click the Account tab.
7. Under “Account expires,” select the radio button beside “End of.”
8. Select the date the account should expire.
9. Click OK.
Using a command-line interface
Valid values for the -acctexpires flag include a positive number of days in the future
when the account should expire—for instance, at the end of the day, or to never expire
the account:
> dsmod user "<UserDN>" -acctexpires <NumDays>
Using PowerShell
Set-ADUser -Identity "<UserDN>" -AccountExpirationDate 12/31/2014
Discussion
User accounts can be configured to expire on a certain date. Account expiration is stored
in the accountExpires attribute on a user object. This attribute contains a large integer
representation of the date on which the account expires, expressed in 100-nanosecond
236 | Chapter 6: Users
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
262
|
intervals since January 1, 1601. If you set this attribute to 0, it disables account expiration
for the user (i.e., the account will never expire). Note that this is different from the dsmod
user command, where a value of 0 with -acctexpires will cause the account to expire
at the end of the day.
See Also
MSDN: Account Expiration
6.33. Determining a User’s Last Logon Time
Problem
You want to determine the last time a user logged in to a domain.
Solution
Using a graphical user interface
To view the last logon timestamp in ADUC, do the following:
1. Open the ADUC snap-in (dsa.msc).
2. Click View and confirm that Advanced Features has a checkmark next to it.
3. Right-click on the domain and select Find.
4. Select the appropriate domain.
5. Beside Name, type the name of the user you want to locate and click Find Now.
6. In the Search Results window, double-click on the user.
7. Click the Attribute Editor tab.
8. View the value for the lastLogonTimestamp attribute.
Using a command-line interface
> adfind -b <UserDN> lastLogonTimestamp -tdc
The -tdc and -tdcs switches will display attributes such as lastLogon
Timestamp in a human-readable format.
6.33. Determining a User’s Last Logon Time | 237
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
263
|
Discussion
Trying to determine when a user last logged on has always been a challenge in the
Microsoft NOS environment. In Windows NT, you could retrieve a user’s last logon
timestamp from a PDC or BDC, but this timestamp was the last time the user logged
on to the individual PDC or BDC itself. That means to determine the actual last logon,
you’d have to query every domain controller in the domain. In large environments, this
wasn’t practical. With Windows 2000 Active Directory, things did not improve. A las
tLogon attribute is used to store the last logon timestamp, but unfortunately, this at‐
tribute isn’t replicated. So again, to get an accurate picture, you’d have to query every
domain controller in the domain for the user’s last logon attribute and keep track of the
most recent one.
Since the Windows Server 2003 forest functional level became available, we have had a
viable solution. A new attribute called lastLogonTimestamp was added to the schema
for user objects. This attribute is similar to the lastLogon attribute that was available
previously, with two distinct differences. First, and most importantly, this attribute is
replicated. That means when a user logs in, the lastLogonTimestamp attribute will get
populated and then replicate to all domain controllers in the domain.
The second difference is that since lastLogonTimestamp is replicated, special safeguards
needed to be put in place so that users who logged in repeatedly over a short period of
time did not cause unnecessary replication traffic. So, the lastLogonTimestamp is up‐
dated only if the last update occurred between 9 and 14 days ago by default. (This
window is configurable by modifying the msDS-LogonTimeSyncInterval on the domain
NC.) This means that the lastLogonTimestamp attribute could be more than a week off
in terms of accuracy with a user’s actual last logon. Ultimately, this shouldn’t be a prob‐
lem for most situations because lastLogonTimestamp is intended to address the com‐
mon problem where administrators want to run a query and determine which users
have not logged in over the past month or more.
See Also
Recipe 6.34 for finding users who have not logged on recently; “The LastLogonTimeS‐
tamp Attribute—What it was designed for and how it works”
6.34. Finding Users Who Have Not Logged On Recently
Problem
You want to determine which users have not logged on recently.
238 | Chapter 6: Users
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
264
|
Solution
Using a graphical user interface
1. Open the ADUC snap-in (dsa.msc).
2. In the left pane, right-click on the domain and select Find.
3. Beside Find, select Common Queries.
4. Select the number of days beside “Days since last logon.”
5. Click the Find Now button.
Using a command-line interface
You can locate users who have not logged on for a certain amount of time using either
the built-in DSQuery tool or the OldCmp utility from joeware:
> dsquery user -inactive <NumWeeks>
OldCmp can create a report of all user objects based on several criteria. To create a
report of all users in the adatum.com domain who haven’t logged on in more than 90
days, for example, use the following syntax:
> oldcmp -report -users -b dc=adatum,dc=com -llts -age 90 -sh
Using PowerShell
You can also locate users who have not logged on for a certain amount of time using
PowerShell, as shown in the following command that finds users that have not logged
on in 60 days:
$DaysSince = (Get-Date).AddDays(-60)
Get-ADUser -Filter * -Properties LastLogonDate |↵
Where-Object {($_.LastLogonDate -le $DaysSince) ↵
-and ($_.Enabled -eq $True) -and ($_.LastLogonDate -ne $NULL)} |↵
Select Name,LastLogonDate
Discussion
An attribute on user objects called lastLogonTimestamp contains the approximate last
time the user logged on. However, the lastLogonTimestamp attribute has a certain
amount of latency associated with it to cut down on replication traffic; the date contained
in this attribute can be anywhere from nine to 14 days off in a default domain. This
latency can be made longer or shorter by modifying the attribute msDSLogonTimeSyncInterval of the Domain NC.
6.34. Finding Users Who Have Not Logged On Recently | 239
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
265
|
Using PowerShell
PowerShell has a property named LastLogonDate that is a human-friendly conversion
of the lastLogonTimestamp attribute. This allows for easy PowerShell queries involving
finding inactive users.
See Also
Recipe 6.29 for more on computing large integer timestamps; Recipe 6.33 for more on
finding a user’s last logon timestamp
6.35. Viewing and Modifying a User’s Permitted
Logon Hours
Problem
You want to see the hours that a user is permitted to log on to the network.
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. Right-click on the user and select Properties. From the Account tab, click on Logon
Hours.
4. Select the hours that you want to allow or disallow, and click Logon Permitted or
Logon Denied. Click OK.
5. Click OK.
Using PowerShell
## user DN
$userDN = "LDAP://<UserDN>"
## powers of two in a single byte
## can use [System.Math]::Pow(), but this is faster
$pow2 = @(1, 2, 4, 8, 16, 32, 64, 128)
## bit-state - a bit is either off (0) or on (1)
$onoff = @("0", "1")
240 | Chapter 6: Users
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
266
|
function dump($byte)
{
$result = ""
for ($i = 0; $i -lt 8; $i++)
{
$result += $onoff[($byte -band $pow2[$i]) -ne 0]
}
return $result
}
# days of the week, zero based
$days = @("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",↵
"Friday", "Saturday")
$day = 0
# main
$obj = [ADSI]$userDN
$arr = $obj.logonHours.Value
for ($i = 0; $i -lt $arr.Length; $i += 3)
{
$days[$day]
(dump $arr[$i]) + " " + (dump $arr[$i+1]) + " " + (dump $arr[$i+2])
$day += 1
}
Discussion
Using PowerShell
The logonHours attribute of a user object is represented as an octet string, rather than
a simple string like most of the other attributes we’ve discussed. As a result, manipulating
it directly is a bit trickier than simply inserting a new string in place of an old one. An
octet string is just another name for an array of bytes containing arbitrary binary data.
For the logonHours attribute, each hour of a day is represented as a single bit within a
byte. Each byte contains eight (8) bits, so it takes three bytes to represent all of the hours
in a day. It goes from low-order to high-order (i.e., the low-order bit in the lowest byte
for a given day is midnight to 1:00 a.m.). The information is stored in the logonHours
attribute in UTC and translated by the user interface into local time. Finally, since there
are seven days in a week, and each day takes three bytes of information, the attribute
will have 21 elements.
In the PowerShell example, we pregenerate an array containing the powers-of-2 con‐
tained with a byte and process each day as a subarray of the entire attribute. Using the
bitwise and function in PowerShell allows us to map binary values directly into array
subscripts, which reduces the complexity of the routine.
6.35. Viewing and Modifying a User’s Permitted Logon Hours | 241
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
267
|
See Also
MS KB 816666 (How to Limit User Logon Time in a Domain in Windows Server 2003);
MSDN: Logon-Hours attribute [AD Schema]
6.36. Viewing a User’s Managed Objects
Problem
You want to view the objects that are managed by a user.
Solution
Using a graphical user interface
1. Open ADSI Edit.
2. If an entry for the naming context you want to browse is not already displayed, do
the following:
a. Right-click on ADSI Edit in the right pane and click “Connect to.”
b. Fill in the information for the naming context, container, or OU you want to
add an object to. Click on the Advanced button if you need to enter alternate
credentials.
3. In the left pane, browse to the naming context, container, or OU of the object you
want to view. Once you’ve found the object, right-click on it and select Properties.
4. View the managedObjects attribute.
Using a command-line interface
> adfind -b "<UserDN>" managedObjects
Using PowerShell
To retrieve a user’s managedObjects property with PowerShell, use the following syntax:
Get-ADUser -Identity "<UserDN>" -Properties managedObjects |↵
Select -ExpandProperty managedObjects
Discussion
The managedObjects attribute is linked to the managedBy attribute that can be set on
certain objects in Active Directory, such as computers, OUs, and groups. Setting the
managedBy attribute provides a quick way to define who owns an object. If you do use
242 | Chapter 6: Users
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
268
|
it, you can use the managedObjects attribute on user, contact, or group objects to get
the list of objects for which the user has been configured in the managedBy attribute.
6.37. Creating a UPN Suffix for a Forest
Problem
You want users to have a different UPN suffix from the default provided by your forest.
Solution
Using a graphical user interface
1. Open the Active Directory Domains and Trusts snap-in (domain.msc).
2. In the left pane, right-click Active Directory Domains and Trusts and select
Properties.
3. Under Alternative UPN suffixes, type the name of the suffix you want to add.
4. Click Add and then click OK.
Using a command-line interface
> admod -config -rb cn=Partitions uPNSuffixes:+:treyresearch.com
The attributeName:+:attributeValue syntax will add an additional
value to an existing list of values in a multivalued attribute. Using at
tributeName::attributeValue would overwrite the existing values
with the value you specify.
Using PowerShell
Set-ADForest -Identity <ForestRootDomainName> -UPNSuffixes @{Add="<NewSuffix>"}
Discussion
The UPN allows users to log on with a friendly name that may even correspond to their
email address. UPN logons also do not require the domain to be known so that it can
be abstracted away from the user. You may need to create an additional UPN suffix (e.g.,
@adatum.com) if you want UPNs to map to email addresses, but your AD forest is rooted
at a different domain name (e.g., ad.adatum.com) from the domain name used in email
addresses (e.g., treyresearch.com).
6.37. Creating a UPN Suffix for a Forest | 243
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
269
|
See Also
MS KB 243280 (Users Can Log On Using User Name or User Principal Name); “Add
User Principal Name Suffixes”; MS KB 269441 (How to Use ADSI to List the UPN
Suffixes that Are Defined in Active Directory)
6.38. Restoring a Deleted User
Problem
You want to restore a user object that has been inadvertently deleted.
This recipe assumes that the Active Directory Recycle Bin was enabled
prior to the deletion. If you have not enabled the AD Recycle Bin, you
can do so from the Tasks pane in the Active Directory Administrative
Center.
Solution
Using a graphical user interface (steps specific to Windows Server 2012)
1. Launch the AD Administrative Center.
2. Select the domain and navigate to the Deleted Objects container.
3. Locate the deleted object in the container.
4. Right-click the object and select Restore.
Discussion
In most cases, it is sufficient when restoring a deleted object within Active Directory to
simply perform an authoritative restore of the individual object. Performing this au‐
thoritative restore will allow the restored user object to be replicated to other DCs within
the domain along with all attributes that were present at the time that the System State
backup was taken.
See Also
MS KB 216993 (Useful Shelf Life of a System-State Backup of Active Directory); MS KB
840001 (How to Restore Deleted User Accounts and Their Group Memberships in Ac‐
tive Directory); Chapter 16 for more on recovering and restoring Active Directory
244 | Chapter 6: Users
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
270
|
6.39. Protecting a User Against Accidental Deletion
Problem
You want to prevent a user object from being accidentally deleted by an administrator
who selects the incorrect option in Active Directory Users and Computers.
Solution
Using a graphical user interface
1. Open Active Directory Users and Computers. Click on View and confirm that Ad‐
vanced Features is selected.
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 object 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 <User DN> /d EVERYONE:SDDT
Using PowerShell
Set-ADObject -Identity "<User 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 group 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 manually re‐
move the deny ACE associated with it.
By 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.
6.39. Protecting a User Against Accidental Deletion | 245
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
271
| null |
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
272
|
CHAPTER 7
Groups
7.0. Introduction
A group is a simple concept that has been used in many different types of standalone
and networked systems over the years. In generic terms, a group is just a collection of
objects. Groups are often used to apply security in an efficient manner, where you create
a collection of users and assign certain permissions or rights to that group, rather than
to each individual user within the group. When applying security settings, it’s much
easier to use a group than to use individual users, because you only need to apply the
security setting once per group instead of once per user. In addition, groups are also
frequently used to send email messages to an entire group of users at once rather than
requiring the sender to address each person individually.
In Active Directory, groups are flexible objects that can contain virtually any other type
of object as a member, although they’ll generally contain only users, inetOrgPersons,
computers, and other groups. Active Directory groups can be used for many different
purposes, including controlling access to resources, defining a filter for the application
of group policies, and serving as an email distribution list.
The ways in which a group can be used in an Active Directory forest are defined by the
group’s scope and type. The type of a group can be either security or distribution. Security
groups can be used to grant or restrict access to Windows resources, whereas distribu‐
tion groups can be used only as a simple grouping mechanism for sending email
messages or for some other non-Windows security-related function. Both security and
distribution groups can be used as email lists, but only security groups can be used to
assign access to resources.
The scope of a group determines where members of the group can be located within the
forest and where in the forest you can use the group in an ACL. The supported group
scopes include universal, global, and domain local. Universal groups and domain local
groups can have members that are part of any domain in the same forest (or, in the case
247
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
273
|
of domain local groups, a separate forest if a cross-forest trust exists), whereas global
groups can only have members that are part of the same domain that the group is
contained in. When assigning permissions to group objects, universal and global groups
can be assigned permissions to resources anywhere in the forest (or any trusted forest),
whereas domain local groups can only be assigned permissions to resources in the same
domain. (In this way, domain local and global groups are functional opposites of each
other.)
The Anatomy of a Group
Groups are represented in Active Directory by group objects. Table 7-1 contains a list
of some of the noteworthy attributes that are available on group objects.
Table 7-1. Attributes of group objects
Attribute Description
cn Relative distinguished name of group objects.
whenCreated Timestamp of when the OU was created.
description Text description of the group.
groupType Flag containing the group scope and type. See Recipe 7.8 for more information.
info Additional notes about a group.
primaryGroupToken Local RID for the group. This matches the primaryGroupID attribute that is set on user objects.
managedBy DN of a user or group that is the owner of the group.
managedObjects List of DNs of objects for which this group is listed in the managedBy attribute.
Member List of DNs of members of the group.
memberOf List of DNs of the groups this group is a member of.
whenChanged Timestamp of when the OU was last modified.
sAMAccountName Down-level account name for the group. Typically this is the same as the cn attribute.
wWWHomePage URL of the home page for the group.
sAMAccountType Describes the type of account that was created for an object, such as a domain object, a groupobject,
a normal user account, and so on.
248 | Chapter 7: Groups
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
274
|
7.1. Creating a Group
Problem
You want to create a group.
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 Group.
4. Enter the name of the group, enter the sAMAccountName, select the group scope
(Domain local, Global, or Universal), and select the group type (Security or
Distribution).
5. Enter any other desired information into the optional fields and then click OK.
Using a command-line interface
In the following example, <GroupDN> should be replaced with the DN of the group to
create, <GroupScope> should be l, g, or u for domain local, global, and universal groups,
respectively, and -secgroup should be set to yes if the group is a security group or no
otherwise. Another recommended option is to set -desc for specifying a group
description:
> dsadd group "<GroupDN>" -scope <GroupScope> -secgrp yes|no -desc "<GroupDesc>"
You can also create a group object with admod, using the following syntax:
> admod -b "<GroupDN>" objectClass::group groupType::↵
"<GroupType>" sAMAccountName::"<Pre-Windows2000Name>" -add
For example, to create a global security group called “Finance Users” in the Finance OU
of the adatum.com domain, you can use either of the following commands:
> dsadd group "cn=Finance Users,ou=Finance,dc=adatum,dc=com"-scope g -secgrp yes
> admod-b "cn=Finance Users,ou=Finance,dc=adatum,dc=com" groupType::-2147483646↵
sAMAccountName::"Finance Users" -add
In the case of AdMod, you must specify the numeric value for the group type, which
can be any one of those listed in Table 7-2.
7.1. Creating a Group | 249
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
275
|
Table 7-2. Numeric values for group types
Group type Numeric value
Universal Distribution Group 8
Universal Security Group −2147483640
Domain Local Distribution Group 4
Domain Local Security Group −2147483644
Global Distribution Group 2
Global Security Group −2147483646
These values are defined in the ADS_GROUP_TYPE_ENUM enumeration; see Recipe 7.8 for
more information.
If you omit the sAMAccountName attribute when creating the group, it
will be automatically populated with a random string.
Using PowerShell
To create a group using PowerShell, run the following command:
New-ADGroup -Name "Finance Users" -SamAccountName FinanceUsers↵
-GroupCategory Security -GroupScope Global -DisplayName "Finance Users"↵
-Path "ou=Finance,dc=adatum,dc=com" -Description "Finance Department Users"
Discussion
In each solution, a group was created with no members. For more information on how
to add and remove members, see Recipe 7.5.
The groupType attribute contains a flag indicating both group scope and type. The
available flag values are defined in the ADS_GROUP_TYPE_ENUM enumeration. Recipe 7.8
contains more information on setting the group scopes and types.
Using a graphical user interface
The Active Directory Administrative Center is used to perform this solution. This allows
you to completely configure the group during the creation process (whereas, if you used
ADUC to create the group, you would have had to create the group and then go back
into the properties to completely configure it).
See Also
Recipe 7.5 for adding and removing group members; “Understanding Group
Accounts”; MSDN: ADS_ GROUP_TYPE_ENUM
250 | Chapter 7: Groups
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
276
|
7.2. Viewing the Permissions of a Group
Problem
You want to list the AD object permissions that have been assigned to a group object.
Solution
Using a graphical user interface
1. Open the Active Directory Users and Computers (ADUC) snap-in (dsa.msc). Click
on View and ensure that there is a checkmark next to Advanced Features.
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. Enter the name of the group and click Find Now.
5. Double-click on the group in the bottom results pane.
6. Click on the Security tab. The users and groups that have been assigned permissions
to the object are listed in the bottom pane; select each entry to view the permissions
that have been assigned to it.
7. Click on Advanced to view the owner of the group, as well as any auditing that has
been configured.
Using a command-line interface
> dsacls "<GroupDN>"
You can also obtain this information using AdFind, as follows:
adfind -gcb -f name=<Group Name> ntsecuritydescriptor -sddl++ -resolvesids
Using PowerShell
If you have Exchange 2007 or later management tools installed on your workstation,
you can retrieve DACL and SACL information using the following Exchange cmdlet:
Get-ADPermission -Identity <Group Name>
Discussion
In an Active Directory environment, you can set permissions on an object within the
directory in much the same way that you can set NTFS permissions on files and folders.
7.2. Viewing the Permissions of a Group | 251
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
277
|
Each AD object has a Security Descriptor (SD) associated with it that is made up of a
Discretionary Access Control List (DACL) that dictates which users and groups can
access an object, and a System Access Control List (SACL) that controls which users’ or
groups’ activities should be audited. The DACL and SACL are each made up of one or
more Access Control Entries (ACEs), one for each user or group and its associated
permission.
See Also
MSDN: Creating a DACL [Security]; MSDN: Order of ACEs in a DACL [Security];
MSDN: SACL Access Right [Security]; MSDN: Retrieving an Object’s SACL [Security]
7.3. Viewing the Direct Members of a Group
Problem
You want to view the direct members of a group.
Solution
Using a graphical user interface
1. Open the Active Directory Administrative Center.
2. In the right pane, enter the name of the group 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 group to open the group
properties.
4. Scroll down to the Members area to view the members.
Using a command-line interface
You can enumerate the direct members of a group using the built-in DSGet utility, or
AdFind. Use the following DSGet syntax to view the members:
> dsget group "<GroupDN>" -members
To list group members with AdFind, use the following syntax:
> adfind -b "<GroupDN>" member
252 | Chapter 7: Groups
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
278
|
Using PowerShell
To enumerate the direct group membership of the Domain Admins group, run the
following PowerShell command:
Get-ADGroupMember -Identity "Domain Admins" | Select Name
Discussion
The member attribute of a group object contains the distinguished names of the direct
members of the group. By direct members, we mean the members that have been directly
added to the group. This is in contrast to indirect group members, which are members
of the group due to nested group membership. See Recipe 7.4 for how to find the nested
membership of a group.
The memberOf attribute is a backlink to member. This means that, for each group mem‐
bership listed in a group’s member attribute, the DN of the group itself appears in that
user/computer/group’s memberOf attribute. Think of it this way: if the FinanceUsers
group has Jane as a member, then Jane is a member of the FinanceUsers group. In this
way, Active Directory uses forward links and backlinks to maintain consistency between
groups and their membership.
See Also
Recipe 7.4 for viewing nested group membership
7.4. Viewing the Nested Members of a Group
Problem
You want to view the nested membership of a 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 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. Enter the name of the group and click Find Now.
5. Double-click on the group in the bottom results pane.
7.4. Viewing the Nested Members of a Group | 253
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
279
|
6. Click the Members tab.
7. Double-click on each group member to view its membership.
Using a command-line interface
> dsget group "<GroupDN>" -members -expand
You can also obtain this information using the joeware MemberOf utility:
> memberof -group <GroupDN>
Using PowerShell
The simplest method of listing nested group membership in PowerShell is to use the
–recursive switch, as shown in the following command:
Get-ADGroupMember -Identity "Domain Admins" -recursive | Select Name
Discussion
As described in Recipe 7.3, group membership is stored in the multivalued member
attribute on group objects. But the member attribute will not show the complete picture
because of group nesting. To view the complete group membership, you have to recur‐
sively search through the group membership of each group. (The exception to this is
the memberof command-line utility, which correctly displays primary group
memberships.)
See Also
Recipe 7.3 for viewing group membership; MSDN: IADsMember
7.5. Adding and Removing Members of a Group
Problem
You want to add or remove members of a 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 Com‐
puters in the left pane, select Connect to Domain, enter the domain name, and click
OK.
254 | Chapter 7: Groups
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
280
|
3. In the left pane, right-click on the domain and select Find.
4. Enter the name of the group and click Find Now.
5. Double-click on the group in the bottom results pane.
6. Click the Members tab.
7. To remove a member, click on the member name, click the Remove button, click
Yes, and click OK.
8. To add a member, click on the Add button, enter the name of the member, and click
OK twice.
Using a command-line interface
The -addmbr option in dsmod adds a member to a group:
> dsmod group "<GroupDN>" -addmbr "<MemberDN>"
To add a group member with admod, use the following syntax:
> admod -b "<GroupDN>" member:+:"<MemberDN>"
The -rmmbr option in dsmod removes a member from a group:
> dsmod group "<GroupDN>" -rmmbr "<MemberDN>"
To remove a group member with admod, use the following syntax:
> admod -b "<GroupDN>" member:-:"<MemberDN>"
The -chmbr option in dsmod replaces the complete membership list:
> dsmod group "<GroupDN>" -chmbr "<Member1DN Member2DN ... >"
To replace the membership of a group with admod, use the following command:
> admod -b "<GroupDN>" member:+-:"<Member1DN>;<Member2DN>;<Member3DN>"
Using PowerShell
To add and remove users from groups using PowerShell, use the following syntax:
Add-ADGroupMember -Identity "<GroupDN>" -Members "<UserDN>"
Remove-ADGroupMember -Identity "<GroupDN>" -Members "<UserDN>" -Confirm:$False
Discussion
Since there are no restrictions on what distinguished names you can put in the mem
ber attribute, you can essentially have any type of object as a member of a group. Al‐
though OUs are typically used to structure objects that share certain criteria, group
objects can be used to create loose collections of objects.
7.5. Adding and Removing Members of a Group | 255
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
281
|
The benefit of using group objects as a collection mechanism is that the same object can
be a member of multiple groups, whereas an object can only be a part of a single OU.
Another key difference is that you can assign permissions on resources to groups be‐
cause they are considered security principals in Active Directory, whereas OUs are not.
See Also
Recipe 7.3 for viewing group membership; MSDN: IADsGroup::Add; MSDN:
IADsGroup::Remove
7.6. Moving a Group Within a Domain
Problem
You want to move a group to a different OU or container within the same domain.
Solution
Using a graphical user interface
1. Open the Active Directory Administrative Center.
2. In the right pane, enter the name of the group 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 group and then click Move.
4. In the Move dialog box, browse to the desired destination container, click to high‐
light it, and then click OK to complete the move.
Using a command-line interface
To move an object to a new parent container within the same domain, you can use either
DSMove or AdMod, as follows:
> dsmove "<GroupDN>" -newparent "<NewParentDN>"
or:
> admod -b "<GroupDN>" -move "<NewParentDN>"
Using PowerShell
To move a group with PowerShell, use the following syntax:
Move-ADObject -Identity "<GroupDN>" -TargetPath "<New OU DN>"
256 | Chapter 7: Groups
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
282
|
Discussion
Using a command-line interface
The DSMove utility can work against any type of object, including groups. The first
parameter is the DN of the group that you want to move. The second parameter is the
new parent container of the group. The -s parameter can additionally be used to des‐
ignate a specific server to work against.
See Also
Recipe 4.20 for moving an object to a different OU; Recipe 4.21 for moving an object
to a different domain; Recipe 7.8 for changing group scope and type; “Understanding
Group Accounts”; MSDN: IADsContainer::MoveHere
7.7. Moving a Group to Another Domain
Problem
You want to move a group to a different domain in the same forest.
Solution
Using a graphical user interface
To migrate user, computer, group, or OU objects between domains in the same forest,
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 Group
Account Migration Wizard.
3. Click Next on the welcome screen.
4. On the Domain Selection screen, enter the DNS or NetBIOS name of the source
and target domains and click Next.
5. On the Group Select Option screen, select the option to select the group from the
domain and click Next.
6. On the Group Selection screen, add the group objects that you wish to migrate and
click Next. (You cannot migrate built-in or well-known groups such as Domain
Users or Domain Admins using this process.)
7. On the Organizational Unit Selection screen, enter the name of the target OU or
select Browse to open an object picker in the target domain. Click Next to continue.
7.7. Moving a Group to Another Domain | 257
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
283
|
8. On the Group Options screen, select one or more of the following and click Next:
“Update user rights”
Copies any user rights that are assigned in the source domain to the target
domain.
“Copy group members”
Specifies whether the user objects that belong to the group should be migrated
along with the group. If you don’t select this option, the group will be created
in the target domain with no members.
“Update previously migrated objects”
Supports migrations that take place over time by comparing the source and
target groups and migrating any changes that have taken place.
“Fix membership of group”
Adds any migrated user accounts to groups in the target domain if the user
accounts were members of the source groups in the source domain.
“Migrate group SIDs to target domain”
Adds the security identifiers (SIDs) of the migrated group accounts in the
source domain to the SID history of the new group in the target domain.
9. On the Naming Conflicts screen, select whether you want to migrate group objects
that conflict with objects in the target domain and click Next.
10. Click Finish to complete the migration.
Using a command-line interface
To migrate a group from the command line using the ADMT utility, use the following
syntax:
> ADMT GROUP /N "<GroupName>" /IF:YES /SD:"<SourceDomainDN>"↵
/TD:"<TargetDomainDN>" /TO:"<TargetOUName>"
Using PowerShell
To migrate a group by using PowerShell, use the following syntax:
Move-ADObject -Identity "<GroupDN>" -TargetPath "<TargetOUDN>"↵
-TargetServer "<TargetServerFQDN>"
Discussion
The only type of group that can be moved between domains using the built-in operating
system tools is universal groups; additionally, the RID Master for both the source and
the target domains needs to be available in order to complete the move. If you want to
move a global or domain local group to a different domain, first convert it to a universal
group, move the group, and then convert it back to a global or domain local group.
258 | Chapter 7: Groups
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
284
|
When you convert a group between types, you may encounter problems because dif‐
ferent groups have different membership restrictions. See the Recipe 7.0 section of this
chapter for more information on group type membership restrictions.
Another way to accomplish interdomain (intraforest or interforest) group moves is by
using ADMT, which might be quite useful if you need to move a large number of groups.
With ADMT, you can move and restructure groups without needing to go to all the
trouble of converting the group to a universal group and then modifying the group
membership. For more on the latest version of ADMT, see “Active Directory Migration
Tool (ADMT) Guide: Migrating and Restructuring Active Directory Domains”.
7.8. Changing the Scope or Type of a Group
Problem
You want to change the scope or type of a 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 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. Enter the name of the group you want to modify and click Find Now.
5. Double-click on the group in the results pane.
6. In the group properties dialog box, select the new scope or type, and click OK.
Using a command-line interface
The following example changes the group scope for <GroupDN> to <NewScope>, which
should be l for domain local group, g for global group, or u for universal group:
> dsmod group "<GroupDN>" -scope <NewScope>
The following example changes the group type for <GroupDN>. For the -secgrp switch,
specify yes to change to a security group or no to make the group a distribution group:
> dsmod group "<GroupDN>" -secgrp yes|no
To change the scope and/or type of a group using AdMod, use the following syntax:
7.8. Changing the Scope or Type of a Group | 259
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
285
|
> admod -b "<GroupDN>" groupType::<GroupType>
Just as when you created a group using AdMod, you must specify the numeric value for
the group type. Refer to Recipe 7.1 for more information.
Using PowerShell
To modify a group’s type or scope with PowerShell, use the following syntax. Use
'Security' or 'Distribution' as the group category, and 'Global', 'Universal', or
'DomainLocal' as the group scope:
Set-ADGroup "<Group Name>"-GroupCategory <GroupCategory> -GroupScope <GroupScope>
Discussion
Group scope and type are stored as a flag in the groupType attribute on group objects.
To directly update groupType, you must logically OR the values associated with each
type and scope, as shown in the API solution, or use the raw numeric values listed in
Recipe 7.1 when using AdMod. Note that there is no specific value for the distribution
list type. If you want to create a distribution list, just do not include the
ADS_GROUP_TYPE_SECURITY_ENABLED flag when setting groupType. Additional group
types also are available through Authorization Manager.
For a good description of the usage scenarios for each group type, see
Active Directory, Fifth Edition, by Brian Desmond et al. (O’Reilly).
See Also
Recipe 7.1; “Understanding Group Accounts”; MSDN: ADS_GROUP_TYPE_ENUM;
MSDN: What Type of Group to Use
7.9. Modifying Group Attributes
Problem
You want to modify one or more attributes of an object.
Solution
Using a graphical user interface
1. Open the Active Directory Administrative Center.
260 | Chapter 7: Groups
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
286
|
2. In the right pane, enter the name of the group in the Global Search box, select the
desired domain in the scope, and then click the search icon.
3. In the search results pane, double-click the group to display the group properties.
4. Scroll down to the Extensions section and then click the Attribute Editor tab.
5. Find the attribute that you want to modify, click to highlight the attribute, and then
click Edit.
6. Enter the new value for the attribute and then click OK.
7. Click OK in the group properties window to complete the modification.
Using a command-line interface
Create an LDIF file called modify_object.ldf with the following contents:
dn: cn=Finance Users,cn=users,dc=adatum,dc=com
changetype: modify
add: description
description: Members of the Finance Department
-
Then run the following command:
> ldifde -v -i -f modify_object.ldf
To modify a group using AdMod, you’ll use the following general syntax:
> admod-b "<GroupDN>" <attribute>:<operation>:<value>
For example, you can add a description to a group object using the following syntax:
> C:\>admod -b cn="Finance Users,cn=Users,dc=adatum,dc=com"↵
description::"Members of the Finance Department"
You can also modify group objects with the dsmod group command using the following
syntax:
> dsmod group "<GroupDN>" <options>
The available options for dsmod include the following:
-samid <NewSAMName>
Updates the sAMAccountName attribute of the group object
-desc <NewDescription>
Updates the description attribute of the group object
-secgrp {yes | no}
Configures the group object as a security group (yes) or a distribution group (no)
-scope {l | g | u}
Configures the group scope as domain local (l), global (g), or universal (u)
7.9. Modifying Group Attributes | 261
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
287
|
{-addmbr | -rmmbr | -chmbr} <MemberDN1> <MemberDN2>
Adds the specified objects to the group (addmbr), removes the specified objects
(rmmbr), or replaces the membership list wholesale with only the specified objects
(chmbr)
Using PowerShell
You can modify a group’s properties by using the Set-ADGroup cmdlet, as shown in the
following example:
Set-ADGroup -Identity "<GroupDN>" -GroupType "<GroupType>"↵
-GroupScope "<GroupScope>" -Description "<Description>"
Discussion
Using a graphical user interface
If the parent container of the object you want to modify has a lot of objects in it, you
may want to add a new connection entry for the DN of the target object. This will be
easier than trying to hunt through a container full of objects. You can do this by rightclicking ADSI Edit and selecting “Connect to” under Connection Point, then selecting
Distinguished Name and entering the DN of the object.
Using a command-line interface
For more on ldifde, see Recipe 4.28.
Using PowerShell
The Set-ADGroup cmdlet has the following parameters that allow you to modify specific
attributes of a group object:
• -ManagedBy
• -Notes
• -Email
• -GroupCategory
• -GroupScope
• -SamAccountName
• -Description
• -DisplayName
• -HomePage
262 | Chapter 7: Groups
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
288
|
See Also
Recipe 4.14; Recipe 4.28
7.10. Delegating Control for Managing Membership
of a Group
Problem
You want to delegate the ability to manage the membership of a 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 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. Enter the name of the group and click Find Now.
5. Double-click on the group in the results pane.
6. Select the Managed By tab.
7. Click the Change button.
8. Locate the group or user to delegate control to and click OK.
9. Check the box beside “Manager can update membership list.”
10. Click OK.
Using a command-line interface
> dsacls <GroupDN> /G <GroupName>@DomainName:WP;member;
In the following example, the SalesAdmin group will be given rights to modify mem‐
bership of the PreSales group:
> dsacls cn=presales,ou=sales,dc=adatum,dc=com /G salesadmins@adatum.com:↵
WP;member;
7.10. Delegating Control for Managing Membership of a Group | 263
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
289
|
Using PowerShell
In PowerShell, you can change the person or group who is listed as the manager of a
group. However, note that the following example does not set the permissions for the
manager to manage the group’s membership:
Set-ADGroup <Group Name> -ManagedBy "<GroupDN>"
You can use a PowerShell console on a computer where the Exchange Server 2007 or
later management tools have been installed to grant the right to manage group
membership:
Add-ADPermission -Identity <Group Name> -User <User or Group Name>↵
-AccessRights WriteProperty -Properties "members"
Discussion
To grant a user or group the ability to manage group membership, you have to grant
the write property (WP) permission on the member attribute of the target group. You can
add this ACE directly using dsacls, or more indirectly with ADUC. ADUC also has a
feature that allows you to simply check a box to grant the ability to modify group mem‐
bership to the object represented by the managedBy attribute.
If you want to configure additional permissions, such as the ability to modify the
description attribute for the group, you will need to go to the Security tab in ADUC
or specify the appropriate attribute with the /G switch with dsacls. For example, this
will grant the write property on the description attribute:
/G <GroupName>@DomainDNSName:WP;description;
See Also
Recipe 14.5 for delegating control in Active Directory
7.11. Resolving a Primary Group ID
Problem
You want to find the name of a user’s primary group.
Solution
Using a graphical user interface
1. Open the ADUC snap-in (dsa.msc).
264 | Chapter 7: Groups
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
290
|
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. Type the name of the user and click Find Now.
5. In the Search Results window, double-click on the user.
6. Click the Member Of tab.
7. The Primary Group name is shown on the bottom half of the dialog box.
Using PowerShell
To find the primary group for a user with PowerShell, use the following syntax:
Get-ADUser -Identity "<UserDN>" -Properties PrimaryGroup | Select PrimaryGroup
Discussion
In the past, when trying to determine a user’s group membership you had to look at the
user’s memberOf attribute, which contains a list of DNs for each group the user is a
member of, as well as the user’s primary group. By default, all users are assigned Domain
Users as their primary group. Therefore, by default all users in a domain are implicitly
members of the Domain Users group. Unfortunately, a user’s primary group does not
show up in the memberOf attribute.
Services for Macintosh and POSIX-based applications are the main
users of primary groups. If you don’t use either of those, you usually
don’t need to worry about changing a user’s primary group.
The primary group is stored in the primaryGroupID attribute on user objects. Un‐
fortunately, the information that’s stored in that attribute is the relative identifier (RID)
of the group, not the DN or even sAMAccountName as you might expect. group objects
have a primaryGroupToken attribute, which contains the same value but is a constructed
attribute. Because Active Directory dynamically constructs it, you cannot utilize it in
search filters. So even if you have the primaryGroupID of a user (e.g., 513), you cannot
do a simple query to find out which group it is associated with. However, with Power‐
Shell and Active Directory Users and Computers, this task is very straightforward.
7.11. Resolving a Primary Group ID | 265
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
291
|
Using PowerShell
The PowerShell solution uses the calculated property named PrimaryGroup, which
allows the solution to be straightforward and similar to querying for typical user
attributes.
See Also
MS KB 297951 (How to Use the PrimaryGroupID Attribute to Find the Primary Group
for a User)
7.12. Enabling Universal Group Membership Caching
Problem
You want to enable universal group membership caching so that a global catalog server
is not needed during most user logins.
Solution
Using a graphical user interface
1. Open the Active Directory Sites and Services snap-in (dssite.msc).
2. In the left pane, browse to the site you want to enable group caching for and click
on it.
3. In the right pane, double-click on the NTDS Site Settings object.
4. Under Universal Group Membership Caching, check the box beside Enable Uni‐
versal Group Membership Caching.
5. If you want to force the cache refresh from a particular site, select a site or else leave
the default set to <Default>.
6. Click OK.
Using a command-line interface
You can use a combination of the dsquery site and dsget site commands to deter‐
mine whether a site has group caching enabled:
> dsquery site -name <SiteName> | dsget site -dn -cachegroups -prefGCSite
You can use ldifde to enable group caching. Create a file called enable_univ_cache.ldf
with the following contents, but change <SiteName> to the name of the site you want
to enable and <ForestRootDN> to the distinguished name of the forest root domain:
266 | Chapter 7: Groups
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
292
|
dn: cn=NTDS Site Settings,cn=<SiteName>,cn=sites,cn=configuration,<ForestRootDN>
changetype: modify
replace: options
options: 32
-
Then use the following command to import the change:
> ldifde -i -f enable_univ_cache.ldf
You can also perform this change in the adatum.com domain by using AdMod with the
following syntax:
> admod -b "cn=NTDS Site Settings,cn=<SiteName>,cn=sites,cn=configuration,↵
dc=adatum,dc=com" options::32
Using PowerShell
You can use the following PowerShell syntax to find out whether a site has universal
group membership caching enabled:
Get-ADReplicationSite "<Site Name>" -Properties UniversalGroupCachingEnabled |↵
FL UniversalGroupCachingEnabled
To enable universal group membership caching on a site by using PowerShell, use the
following syntax:
Set-ADReplicationSite "<Site Name>" -UniversalGroupCachingEnabled $True
Discussion
When a client logs on, the domain controller that authenticates the user needs to contact
a global catalog server in order to fully authenticate the client (however, if the DC that
authenticates the user is itself a GC, then it does not need to contact any other servers
to complete the authentication process). This is necessary because global catalogs are
the only servers that store universal group information, which is needed to completely
determine a user’s group memberships upon logon.
Universal groups can be created and used anywhere in a forest. Objects located anywhere
in a forest can be added as members of a universal group. Since a universal group could
be created in a domain other than where the user object resides, it is necessary to store
universal group membership in the global catalog. That way, during logon, domain
controllers can query a global catalog to determine all universal groups a user is a mem‐
ber of. Microsoft’s primary reason for making this a requirement during logon is that a
user could be part of a universal group that has been explicitly denied access to certain
resources. If universal groups aren’t evaluated, a user could gain access to resources that
are supposed to be restricted.
To remove this limitation, Microsoft introduced universal group caching. Universal
group caching can be enabled on a per-site basis and allows domain controllers to cache
7.12. Enabling Universal Group Membership Caching | 267
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
293
|
universal group information locally, thus removing the need to query the global catalog
during client logon.
You can enable universal group caching manually by enabling the 10000 bit (32 in
decimal) on the options attribute of the NTDS Site Settings object. See Recipe 4.15
for more information on properly setting a bit flag attribute. The Sites and Services
snap-in just requires you to check a box. Another setting can also be configured that
relates to universal group caching. By default, domain controllers will use the site top‐
ology to determine the optimal site to use to query a global catalog server for universal
group information. You can override this feature and explicitly set which site domain
controllers should use by selecting the site in the Sites and Services snap-in or by setting
the attribute msDS-Preferred-GC-Site on the NTDS Site Settings object to the DN
of the target site.
See Also
Recipe 4.15
7.13. Restoring a Deleted Group
Problem
You want to restore a group object that has been inadvertently deleted, as well as restore
its members.
These solutions assume that the Active Directory Recycle Bin was en‐
abled prior to the deletion. If you have not enabled the AD Recycle Bin,
you can do so from the Tasks pane in the Active Directory Adminis‐
trative Center.
Solution
Using a graphical user interface (steps specific to Windows Server 2012)
1. Launch the Active Directory Administrative Center.
2. Select the domain and navigate to the Deleted Objects container.
3. Locate the deleted group in the container.
4. Right-click the group and select Restore.
268 | Chapter 7: Groups
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
294
|
Using PowerShell
To restore the group object and membership, use the following PowerShell command
syntax:
Get-ADObject -Filter {isDeleted -eq $true} -IncludeDeletedObjects |↵
Where-Object {$_.DistinguishedName -match "<GroupName>"} |↵
Restore-ADObject
Discussion
Prior to the introduction of the Active Directory Recycle Bin, the most common way
to restore a deleted object was to perform an authoritative restore by using ntdsutil.
However, the Active Directory Recycle Bin and PowerShell have greatly simplified the
process. While legacy restore methods are still valid and occasionally necessary, many
restores can use the newer and more efficient methods.
Note that in both the GUI solution and the PowerShell solution, the group membership
is restored along with the group object. In situations where you have deleted user objects
and a deleted group object that contained some of the deleted user objects as members,
restore the user objects first before restoring the group object. This will ensure that an
accurate group membership is maintained after the group restore.
See Also
MS KB 216993 (Useful Shelf Life of a System-State Backup of Active Directory);
“Rebooting Windows Server 2012-based Domain Controllers into Directory Services
Restore Mode”; Chapter 16 for more on recovering and restoring Active Directory
7.14. Protecting a Group Against Accidental Deletion
Problem
You want to prevent a group object from being accidentally deleted by an administrator
who selects the incorrect option in Active Directory Users and Computers.
Solution
Using a graphical user interface
1. Open Active Directory Users and Computers. Click on View and confirm that Ad‐
vanced Features is selected.
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.
7.14. Protecting a Group Against Accidental Deletion | 269
|
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
|
295
|
3. Right-click on the group 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 "<GroupDN>" /d EVERYONE:SDDT
Using PowerShell (all versions)
Set-ADObject "<GroupDN>" -ProtectedFromAccidentalDeletion $True
If you have Exchange 2007 or later installed in your environment, you can also use the
following Exchange cmdlet to modify this information:
Add-ADPermission -Identity <Group Name> -User <User or Group Name>↵
-AccessRights Delete,DeleteTree -Deny $true
Discussion
By default, all new OUs that are created in Windows Server 2008 or later will have this
protection enabled; however, no other object types are configured with this default
protection. If you attempt to delete a group 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 manually re‐
move the deny ACE associated with it.
By 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 or later.
7.15. Applying a Fine-Grained Password Policy to a
Group Object
Problem
You want to apply a Fine-Grained Password Policy to a group object in a domain.
Solution
Using a graphical user interface
1. Open Active Directory Administrative Center.
270 | Chapter 7: Groups
|
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.