Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21

Thread: Query disabled users and delete their memberof associations

  1. #16
    bryan Guest

    Re: Query disabled users and delete their memberof associations

    Hi guys

    I have been testing the following script and it is failing on line <41, 58>
    "microsoft vbscript compilation error: Unterminated string constant"

    Any ideas?

    Also, are you able to sanitise the script itself to see if my logic is
    correct?

    Much thanks in advance

    Cheers
    Bry



    ***********************************************

    Option Explicit

    Dim objDSE, objConnection, objCommand, objRecordset, i

    Set objDSE = GetObject("LDAP://rootDSE")

    Set objConnection = CreateObject("ADODB.Connection")
    objConnection.Provider = "ADsDSOObject"
    objConnection.Open

    Set objCommand = CreateObject("ADODB.Command")
    Set objCommand.ActiveConnection = objConnection

    objCommand.CommandText = _
    "<LDAP://DC=TEST,DC=cp,DC=uk>;" & _

    "(&(objectCategory=person)(objectClass=user)(userAccountControl:1.2.840.113556.1.4.803:=2))"


    Set objRecordset = objCommand.Execute

    i = 0
    If Not objRecordset.EOF Then
    While Not objRecordset.EOF
    i = i + 1
    Call ModifyObject(objRecordset.Fields("arrMemberOf"))
    objRecordset.MoveNext
    Wend
    WScript.Echo "Modified " & i & " objects"
    Else
    WScript.Echo "No objects to modify"
    End if

    objRecordset.Close
    objConnection.Close

    Sub ModifyObject(strObjectUser)
    Dim objUser

    Const ADS_PROPERTY_DELETE = 4
    Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D

    Set objUser = GetObject("LDAP://" & strObjectUser"))
    arrMemberOf = objUser.GetEx("MemberOf")

    If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
    WScript.Echo "No Group Memberships Found"
    WScript.Quit

    End If

    For each group in arrMemberOf
    Set objGroup = GetObject("LDAP://" & Group)
    objGroup.PutEx ADS_PROPERTY_DELETE, _
    "member", Array("strObjectUser")

    objGroup.SetInfo
    End Sub

    ***********************************************

    "Joe Richards [MVP]" wrote:

    > Yep it absolutely does. :)
    >
    > --
    > Joe Richards Microsoft MVP Windows Server Directory Services
    > Author of O'Reilly Active Directory Third Edition
    > www.joeware.net
    >
    >
    > ---O'Reilly Active Directory Third Edition now available---
    >
    > http://www.joeware.net/win/ad3e.htm
    >
    >
    > Paul Williams [MVP] wrote:
    > > Thankfully we don't have multiple domains, which means I can avoid such a
    > > royal PITA! ;-)
    > >
    > > We made a concious decision to have one big fat domain, as opposed to four
    > > or five smaller ones. Which is simplifying the design and deployment of a
    > > number of large enterprise apps.
    > >

    >


  2. #17
    Joe Richards [MVP] Guest

    Re: Query disabled users and delete their memberof associations

    This issue is likely the quote character in the line

    Set objUser = GetObject("LDAP://" & strObjectUser"))

    just before the last set of parens.

    --
    Joe Richards Microsoft MVP Windows Server Directory Services
    Author of O'Reilly Active Directory Third Edition
    www.joeware.net


    ---O'Reilly Active Directory Third Edition now available---

    http://www.joeware.net/win/ad3e.htm


    bryan wrote:
    > Hi guys
    >
    > I have been testing the following script and it is failing on line <41, 58>
    > "microsoft vbscript compilation error: Unterminated string constant"
    >
    > Any ideas?
    >
    > Also, are you able to sanitise the script itself to see if my logic is
    > correct?
    >
    > Much thanks in advance
    >
    > Cheers
    > Bry
    >
    >
    >
    > ***********************************************
    >
    > Option Explicit
    >
    > Dim objDSE, objConnection, objCommand, objRecordset, i
    >
    > Set objDSE = GetObject("LDAP://rootDSE")
    >
    > Set objConnection = CreateObject("ADODB.Connection")
    > objConnection.Provider = "ADsDSOObject"
    > objConnection.Open
    >
    > Set objCommand = CreateObject("ADODB.Command")
    > Set objCommand.ActiveConnection = objConnection
    >
    > objCommand.CommandText = _
    > "<LDAP://DC=TEST,DC=cp,DC=uk>;" & _
    >
    > "(&(objectCategory=person)(objectClass=user)(userAccountControl:1.2.840.113556.1.4.803:=2))"
    >
    >
    > Set objRecordset = objCommand.Execute
    >
    > i = 0
    > If Not objRecordset.EOF Then
    > While Not objRecordset.EOF
    > i = i + 1
    > Call ModifyObject(objRecordset.Fields("arrMemberOf"))
    > objRecordset.MoveNext
    > Wend
    > WScript.Echo "Modified " & i & " objects"
    > Else
    > WScript.Echo "No objects to modify"
    > End if
    >
    > objRecordset.Close
    > objConnection.Close
    >
    > Sub ModifyObject(strObjectUser)
    > Dim objUser
    >
    > Const ADS_PROPERTY_DELETE = 4
    > Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D
    >
    > Set objUser = GetObject("LDAP://" & strObjectUser"))
    > arrMemberOf = objUser.GetEx("MemberOf")
    >
    > If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
    > WScript.Echo "No Group Memberships Found"
    > WScript.Quit
    >
    > End If
    >
    > For each group in arrMemberOf
    > Set objGroup = GetObject("LDAP://" & Group)
    > objGroup.PutEx ADS_PROPERTY_DELETE, _
    > "member", Array("strObjectUser")
    >
    > objGroup.SetInfo
    > End Sub
    >
    > ***********************************************
    >
    > "Joe Richards [MVP]" wrote:
    >
    >> Yep it absolutely does. :)
    >>
    >> --
    >> Joe Richards Microsoft MVP Windows Server Directory Services
    >> Author of O'Reilly Active Directory Third Edition
    >> www.joeware.net
    >>
    >>
    >> ---O'Reilly Active Directory Third Edition now available---
    >>
    >> http://www.joeware.net/win/ad3e.htm
    >>
    >>
    >> Paul Williams [MVP] wrote:
    >>> Thankfully we don't have multiple domains, which means I can avoid such a
    >>> royal PITA! ;-)
    >>>
    >>> We made a concious decision to have one big fat domain, as opposed to four
    >>> or five smaller ones. Which is simplifying the design and deployment of a
    >>> number of large enterprise apps.
    >>>


  3. #18
    Paul Williams [MVP] Guest

    Re: Query disabled users and delete their memberof associations

    Joe picked out the typo in the other thread -

    Needs to be

    Set objUser = GetObject("LDAP://" & strObjectUser)


    Basically, you're making the brackets a string. Which you don't want to do.

    There's also too many closing brackets. You only need one, for the
    getObject call.


    --
    Paul Williams
    Microsoft MVP - Windows Server - Directory Services

  4. #19
    bryan Guest

    Re: Query disabled users and delete their memberof associations

    Hi Joe

    First of all, apologies for delay in getting back to you - I have only just
    got back to check this query.

    I shall give it a try and let you know how it goes.

    Many many thanks for your reply.

    Kind rgds
    Bry

  5. #20
    Join Date
    Feb 2007
    Posts
    1

    Re: Query disabled users and delete their memberof associations

    Bryan - were you ever able to get this ? I have been searching for the same thing and have not really come up with anything.
    Any suggestions would be greatly appreciated.

  6. #21
    Join Date
    Jan 2006
    Posts
    605

    Re: Query disabled users and delete their memberof associations

    I just found out a script posted by someone else that accomplishes what I wanted but not sure whether it will work for you or not. The script will search ad for distribution groups that contain disabled user accounts and list the groups and users. I pipe the results to a csv file. Then you run the script with a switch that will remove the disabled users from these lists. Here is a link to the script.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. How to add and delete users in a distribution group?
    By Mulan in forum Windows Software
    Replies: 7
    Last Post: 16-02-2011, 08:11 PM
  2. Hibernate delete query using criterion
    By NinjaZxR in forum Software Development
    Replies: 4
    Last Post: 23-06-2010, 04:06 PM
  3. SQL query to delete a row in database
    By Connect_Me in forum Software Development
    Replies: 3
    Last Post: 05-05-2009, 01:45 PM
  4. LDAP Query to show all users within multiple OUs
    By Dolla in forum Active Directory
    Replies: 1
    Last Post: 21-02-2009, 12:20 AM
  5. DSADD user -memberof usage
    By Norika in forum Active Directory
    Replies: 3
    Last Post: 13-03-2007, 08:51 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,086,936.27520 seconds with 16 queries