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

Discussion in 'Python' started by Dirk Hagemann, May 2, 2007.

  1. 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
    Dirk Hagemann, May 2, 2007
    #1
    1. Advertising

  2. Dirk Hagemann

    Tim Golden Guest

    Dirk Hagemann wrote:
    > 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
    Tim Golden, May 2, 2007
    #2
    1. Advertising

  3. Dirk Hagemann

    Tim Golden Guest

    Tim Golden wrote:
    > Dirk Hagemann wrote:
    >> 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 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
    Tim Golden, May 2, 2007
    #3
  4. On 2 Mai, 17:48, Tim Golden <> 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
    Dirk Hagemann, May 4, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QW5kZXJzQmo=?=

    List members of a active directory group

    =?Utf-8?B?QW5kZXJzQmo=?=, Jun 10, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    586
    =?Utf-8?B?QW5kZXJzQmo=?=
    Jun 10, 2004
  2. zieg
    Replies:
    0
    Views:
    2,022
  3. moi
    Replies:
    2
    Views:
    2,859
    Marc Scheuner
    Apr 22, 2006
  4. Replies:
    2
    Views:
    5,087
  5. Patrick Olurotimi Ige

    problem getting User Group Memebership in Active Directory

    Patrick Olurotimi Ige, May 9, 2005, in forum: ASP .Net Security
    Replies:
    2
    Views:
    242
    Patrick Olurotimi Ige
    May 10, 2005
Loading...

Share This Page