Active Directory: how to delete a user from a group?

D

Dirk Hagemann

Hi!

Does anyone has experience with manipulating MS Active Directory
objects? I'd like to delete some users from a group, but so far I
couldn't find anything about this.
There is some good stuff about retrieving data out of the AD (thanks
to Tim Golden!), but how can I manipulate or change AD objects like
users, computers and groups with Python? Is there somewhere a
documentation or some code?

Dirk
 
T

Tim Golden

Dirk said:
Hi!

Does anyone has experience with manipulating MS Active Directory
objects? I'd like to delete some users from a group, but so far I
couldn't find anything about this.
There is some good stuff about retrieving data out of the AD (thanks
to Tim Golden!), but how can I manipulate or change AD objects like
users, computers and groups with Python? Is there somewhere a
documentation or some code?

I freely admit I don't do too much changing of AD objects,
but my module should at least support the methods for doing
things. Some examples in Active Directory Cookbook:

http://techtasks.com/code/viewbook/2

To delete a user, apparently:

<code>
import active_directory
user = active_directory.find_user ("name-of-user")
# or user = active_directory.AD_object ("user-moniker")
user.DeleteObject (0)
</code>

TJG
 
T

Tim Golden

Tim said:
I freely admit I don't do too much changing of AD objects,
but my module should at least support the methods for doing
things. Some examples in Active Directory Cookbook:

http://techtasks.com/code/viewbook/2

Sorry, you wanted to remove a user *from a group*. Misread.

Translated from http://techtasks.com/code/viewbookcode/1626

<code>
import active_directory
group = active_directory.find_group ("name-of-group")
# or group = active_directory.AD_object ("group-moniker")

user = active_directory.find_user ("name-of-user")
# or user = active_directory.AD_object ("user-moniker")

group.Remove (user.path ())

</code>

Obviously, for something this simple using an extra module
is overkill. You might as well:

<code>
import win32com.client

group = win32com.client.GetObject ("group-moniker")
group.Remove ("user-moniker")

</code>

NB I haven't tried these, I've just translated them
from the Cookbook site!

TJG
 
D

Dirk Hagemann

Sorry, you wanted to remove a user *from a group*. Misread.

Translated fromhttp://techtasks.com/code/viewbookcode/1626

<code>
import active_directory
group = active_directory.find_group ("name-of-group")
# or group = active_directory.AD_object ("group-moniker")

user = active_directory.find_user ("name-of-user")
# or user = active_directory.AD_object ("user-moniker")

group.Remove (user.path ())

</code>

Obviously, for something this simple using an extra module
is overkill. You might as well:

<code>
import win32com.client

group = win32com.client.GetObject ("group-moniker")
group.Remove ("user-moniker")

</code>

NB I haven't tried these, I've just translated them
from the Cookbook site!

TJG

Hi Tim!

The first code does exactly what I want - thanks a lot again for your
help.

Dirk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,836
Latest member
BuyBlissBitesCBD

Latest Threads

Top