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

Dirk Hagemann DirkHagemann at gmail.com
Fri May 4 06:57:44 EDT 2007


On 2 Mai, 17:48, Tim Golden <m... at timgolden.me.uk> wrote:
> Tim Golden wrote:
> >Dirk Hagemannwrote:
> >> 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
>
> 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




More information about the Python-list mailing list