Datasheet
UNDERSTAND HOW POWERSHELL AND ACTIVE DIRECTORY WORK TOGETHER 43
Administering
Service Delivery
PART I
A er you bind to the container, you can create the child object by calling the
Create
method. For this example, you’ll pass in the type of the child object being
created (
user
) and the common name of the object (
cn=Nora Shea
):
PS C:\> $user = $container.Create(“user”, “cn=Nora Shea”)
In a manner similar to changing an object’s properties, this user is only
created locally in PowerShell’s memory. erefore, you need to call the same
CommitChanges
method as you did previously when you were modifying a prop-
erty. is instructs ADSI to write the changes into Active Directory:
PS C:\> $user.CommitChanges()
If you were to now look in Active Directory, you would see Nora Shea’s account
created and in a disabled state. You’ll learn how to work with users in more detail
in Chapter 6, “Administering User and Group Accounts.”
Delete Objects
Deleting an object requires an approach similar to creating an object. You can’t bind
directly to the object that you’re deleting because a er you delete it, it will be gone.
erefore, you need to bind to the parent of the object. To delete the object that you
just created, rst bind to the
Users
container:
PS C:\> $container = [ADSI]”LDAP://cn=users,dc=contoso,dc=com”
en, call the
Delete
method and pass in the object type and the common name of
the object you’re deleting:
PS C:\> $container.Delete(“user”, “cn=Nora Shea”)
As in the past few examples, this object is only deleted from the local copy of the
object in PowerShell. erefore, you need to call the
CommitChanges
method again
to make the change in Active Directory:
PS C:\> $container.CommitChanges()
Beyond the Basics
You now have an overview of the basics of using ADSI to manage Active Directory.
roughout the remainder of this book, you’ll see many more examples using both
ADSI and the new Active Directory PowerShell module. If you understand the
basics as they’re outlined here (working with objects, properties, and methods) then
you’re well equipped to handle some of the more advanced ADSI operations dis-
cussed later.
c01.indd 43c01.indd 43 5/12/2011 1:07:56 PM5/12/2011 1:07:56 PM