vbscript: adsi: ldap: type mismatch with looking for members of specific grouphi all,<br/> <br/> the following script in progress throws a type-mismatch error when it is in the process of reading the member-attribute of a desired group object (which has e.g. two members). i want to find out for each of the initial found groups who is member and distinguish after that those two groups in users and groups (which i want to gain via analyzing the path each object lives with string-strip-operations.  however: why are those members not getting into an array i can work with?<br/> <br/> thanks in advance.<br/> <br/> <br/> <br/> Option Explicit<br/> 'On Error Resume Next<br/> '----------------------------------------------------------------------------<br/> ' Script for adding/removing required Users to/from the Metadir Groups<br/> '----------------------------------------------------------------------------<br/> Const MyName = &quot;MD_Groups.vbs&quot; 'nill aendern<br/> Const MyTask = &quot;Add/Remove Users to/from MD Groups&quot;<br/> '----------------------------------------------------------------------------<br/> Dim i, Wshshell, LogParentFolder, LogFile, LogFileBak, fso, f1<br/> Dim UserDomain<br/> Const LogFileMaxSize     = 500000<br/> <br/> Set Wshshell      = CreateObject(&quot;WScript.Shell&quot;)<br/> Set fso             = CreateObject(&quot;Scripting.FileSystemObject&quot;)<br/> <br/> UserDomain = WshShell.ExpandEnvironmentStrings(&quot;%USERDOMAIN%&quot;)<br/> <br/> LogParentFolder    = &quot;c:\temp\log\md_groups\&quot;<br/> LogFile             = LogParentFolder &amp; &quot;md_groups.log&quot;<br/> LogFileBak          = LogParentFolder &amp; &quot;md_groups.bak&quot;<br/> <br/> <br/> 'prune LogFile<br/> If Not FolderExists (LogParentFolder) Then<br/>    fso.CreateFolder(LogParentFolder)<br/> Else<br/>    If FileExists(LogFile) Then<br/>       Set f1 = fso.GetFile(LogFile)<br/>       If f1.Size &gt; LogFileMaxSize Then<br/>          fso.DeleteFile LogFileBak<br/>          fso.CopyFile LogFile, LogFileBak<br/>          fso.DeleteFile LogFile<br/>       End If<br/>    Else<br/>       fso.CreateTextFile(LogFile)<br/>    End If<br/> End If<br/> <br/> 'do find all groups named MD_*<br/> Dim arrMDGroups, MDGroup<br/> arrMDGroups = ldapquery(&quot;(&amp;(objectclass=group)(name=md_*))&quot;, &quot;distinguishedname&quot;, &quot;ou=md,ou=groups,ou=myou,dc=mydc&quot;, &quot;onelevel&quot;)<br/> <br/> <br/> 'go through all groups and find corresponding &quot;real&quot; groups<br/> For Each MDGroup In arrMDGroups<br/> Dim temp1_strippedCN, temp2_strippedCN, strippedCN<br/> Dim arrLogicalParentGroups<br/> <br/>    Dim arrMDGroupMember, xyz<br/> '   arrMDGroupMember = ldapquery(&quot;(objectclass=group)&quot;, &quot;member&quot;, MDGroup , &quot;base&quot;)<br/>    arrMDGroupMember = ldapquery(&quot;(objectclass=group)&quot;, &quot;member&quot;, &quot;CN=MD_Notes,ou=md,ou=groups,ou=myou,dc=mydc&quot;, &quot;base&quot;)<br/>    For Each xyz In arrMDGroupMember<br/>       Logline xyz<br/>    Next   <br/> <br/>    Logline &quot;Found MD_-Group: &quot; &amp; MDGroup<br/>    <br/>    ' strip out logical parent folder name(s)<br/>    temp1_strippedCN = Split(MDGroup,&quot;,&quot;)<br/>    temp2_strippedCN = Split(temp1_strippedCN(0),&quot;=&quot;)<br/>    strippedCN = Mid(temp2_strippedCN(1),4)<br/>    <br/>    ' find groups md_xxx is made for (xxx &amp; cebra_xxx - groups)<br/>    arrLogicalParentGroups = ldapquery(&quot;(&amp;(objectclass=group)(|(cn=&quot; &amp; strippedCN &amp; &quot;)(cn=CEBRA_&quot; &amp; strippedCN &amp; &quot;)))&quot;, &quot;distinguishedname&quot;, &quot;ou=groups,ou=bank09916,dc=m09916&quot;, &quot;subtree&quot;)<br/>    <br/>    Dim ParentGroup<br/>    For Each ParentGroup In arrLogicalParentGroups<br/>       Logline ParentGroup<br/>    Next<br/>    <br/> Next  <br/> <br/> WScript.Echo &quot;Completed - &quot; &amp; MyTask<br/> Logline &quot;Completed - &quot; &amp; MyTask<br/> LogHeader<br/> <br/> WScript.quit<br/> 'End of Program<br/> <br/> '----------------------------------------------------------------------------<br/> Sub Logline(LineText)<br/>  Dim fso, tf<br/>  Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)<br/>  Set tf = fso.OpenTextFile(Logfile,8,true)<br/>  tf.WriteBlankLines(1)<br/>  tf.writeLine(&quot;***&quot; &amp; MyName &amp; &quot; = &quot; &amp; LineText )<br/>  tf.close()<br/> End Sub<br/> '----------------------------------------------------------------------------<br/> Sub LogLin1(LineText)<br/>  Dim fso, tf<br/>  Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)<br/>  Set tf = fso.OpenTextFile(Logfile,8,true)<br/>  tf.writeLine(String(LEN(MyName)+6,&quot; &quot;) &amp;  LineText )<br/>  tf.close()<br/> End Sub<br/> '----------------------------------------------------------------------------<br/> Sub LogHeader()<br/>  Dim fso, tf<br/>  Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)<br/>  Set tf = fso.OpenTextFile(Logfile,8,true)<br/>  tf.WriteBlankLines(1)<br/>  tf.writeLine(String(50,&quot;=&quot;) &amp; &quot; &quot; &amp; Date &amp; &quot; &quot; &amp; Time &amp; &quot; &quot; &amp; String(8,&quot;=&quot;) )<br/>  tf.close()<br/> End Sub<br/> '----------------------------------------------------------------------------<br/> Function FileExists(File)<br/>   DIM feo<br/>   Set feo = CreateObject(&quot;Scripting.FileSystemObject&quot;)<br/>   FileExists=feo.FileExists(File)<br/> End Function<br/> '----------------------------------------------------------------------------<br/> Function FolderExists(Folder)<br/>   DIM feo<br/>   Set feo = CreateObject(&quot;Scripting.FileSystemObject&quot;)<br/>   FolderExists=feo.FolderExists(Folder)<br/> End Function<br/> '----------------------------------------------------------------------------<br/> ' generic function for doing a search in AD via ldap and generate list with attribute_to_return values of all found objects , <br/> <br/> ' syntax: <br/> ' searchfilter          = ldap-compliant (&amp;(objectlass=inetorgperson)(userprincipalname=rsmi014)) - use adsiedit.msc to find out the name of the attribute of interest<br/> ' attribute_to_return   = use adsiedit.msc to find out the name of the attribute of interest, only one can be defined (for use in a one-dimensional array)<br/> ' searchbase            = base-object from where to start the query, cn=ich,ou=users,ou=..... <br/> ' scope                 = either one: base (the base-object given itself is searched) , onelevel (search amongst siblings of the provided base-object), subtree (search all objects below base-object)<br/> <br/> ' see: http://support.microsoft.com/kb/187529<br/> <br/> Function ldapquery(searchfilter,attribute_to_return,searchbase,scope)<br/> <br/>    Dim objConnection, objCommand, UserDomain, Wshshell, objRecordSet, strResults<br/> <br/>    Set Wshshell = CreateObject(&quot;WScript.Shell&quot;)<br/>    strResults = &quot;&quot;<br/>    UserDomain = WshShell.ExpandEnvironmentStrings(&quot;%USERDOMAIN%&quot;)<br/> <br/>    Set objConnection = CreateObject(&quot;ADODB.Connection&quot;)<br/>    Set objCommand = CreateObject(&quot;ADODB.Command&quot;)<br/>    objConnection.Provider = &quot;ADsDSOObject&quot;<br/>    objConnection.Open &quot;Active Directory Provider&quot;<br/> <br/>    Set objCOmmand.ActiveConnection = objConnection<br/>    objCommand.CommandText = &quot;&lt;LDAP://&quot; &amp; UserDomain &amp; &quot;/&quot; &amp; searchbase &amp; &quot;&gt;;&quot; &amp; searchfilter &amp; &quot;;&quot; &amp; attribute_to_return &amp; &quot;;&quot; &amp; scope<br/>    objCommand.Properties(&quot;Page Size&quot;) = 2000<br/>    Set objRecordSet = objCommand.Execute<br/>    <br/>    Do Until objRecordSet.EOF<br/>       If strResults = &quot;&quot; Then<br/>          strResults = objRecordSet.Fields(attribute_to_return).Value '!schreib den aktuellen Wert des Felds &quot;Name&quot; rein<br/>       Else<br/>          strResults = strResults &amp; &quot;::&quot; &amp; objRecordSet.Fields(attribute_to_return).Value '!schreib den aktuellen Wert des Felds &quot;Name&quot; rein<br/>       End If<br/>       objRecordSet.MoveNext<br/>    Loop<br/> <br/>    ldapquery = Split(strResults, &quot;::&quot;)<br/> <br/>    objConnection.Close<br/>    Set objConnection = Nothing <br/>    Set objCommand = Nothing <br/>    Set objRecordSet = Nothing <br/>    <br/> End Function<br/> '----------------------------------------------------------------------------© 2009 Microsoft Corporation. All rights reserved.Thu, 02 Jul 2009 14:22:23 Z76e44e9e-e42c-4ba1-be47-b0f304acbdbfhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/76e44e9e-e42c-4ba1-be47-b0f304acbdbf#76e44e9e-e42c-4ba1-be47-b0f304acbdbfhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/76e44e9e-e42c-4ba1-be47-b0f304acbdbf#76e44e9e-e42c-4ba1-be47-b0f304acbdbfFlorianZhttp://social.technet.microsoft.com/Profile/en-US/?user=FlorianZvbscript: adsi: ldap: type mismatch with looking for members of specific grouphi all,<br/> <br/> the following script in progress throws a type-mismatch error when it is in the process of reading the member-attribute of a desired group object (which has e.g. two members). i want to find out for each of the initial found groups who is member and distinguish after that those two groups in users and groups (which i want to gain via analyzing the path each object lives with string-strip-operations.  however: why are those members not getting into an array i can work with?<br/> <br/> thanks in advance.<br/> <br/> <br/> <br/> Option Explicit<br/> 'On Error Resume Next<br/> '----------------------------------------------------------------------------<br/> ' Script for adding/removing required Users to/from the Metadir Groups<br/> '----------------------------------------------------------------------------<br/> Const MyName = &quot;MD_Groups.vbs&quot; 'nill aendern<br/> Const MyTask = &quot;Add/Remove Users to/from MD Groups&quot;<br/> '----------------------------------------------------------------------------<br/> Dim i, Wshshell, LogParentFolder, LogFile, LogFileBak, fso, f1<br/> Dim UserDomain<br/> Const LogFileMaxSize     = 500000<br/> <br/> Set Wshshell      = CreateObject(&quot;WScript.Shell&quot;)<br/> Set fso             = CreateObject(&quot;Scripting.FileSystemObject&quot;)<br/> <br/> UserDomain = WshShell.ExpandEnvironmentStrings(&quot;%USERDOMAIN%&quot;)<br/> <br/> LogParentFolder    = &quot;c:\temp\log\md_groups\&quot;<br/> LogFile             = LogParentFolder &amp; &quot;md_groups.log&quot;<br/> LogFileBak          = LogParentFolder &amp; &quot;md_groups.bak&quot;<br/> <br/> <br/> 'prune LogFile<br/> If Not FolderExists (LogParentFolder) Then<br/>    fso.CreateFolder(LogParentFolder)<br/> Else<br/>    If FileExists(LogFile) Then<br/>       Set f1 = fso.GetFile(LogFile)<br/>       If f1.Size &gt; LogFileMaxSize Then<br/>          fso.DeleteFile LogFileBak<br/>          fso.CopyFile LogFile, LogFileBak<br/>          fso.DeleteFile LogFile<br/>       End If<br/>    Else<br/>       fso.CreateTextFile(LogFile)<br/>    End If<br/> End If<br/> <br/> 'do find all groups named MD_*<br/> Dim arrMDGroups, MDGroup<br/> arrMDGroups = ldapquery(&quot;(&amp;(objectclass=group)(name=md_*))&quot;, &quot;distinguishedname&quot;, &quot;ou=md,ou=groups,ou=myou,dc=mydc&quot;, &quot;onelevel&quot;)<br/> <br/> <br/> 'go through all groups and find corresponding &quot;real&quot; groups<br/> For Each MDGroup In arrMDGroups<br/> Dim temp1_strippedCN, temp2_strippedCN, strippedCN<br/> Dim arrLogicalParentGroups<br/> <br/>    Dim arrMDGroupMember, xyz<br/> '   arrMDGroupMember = ldapquery(&quot;(objectclass=group)&quot;, &quot;member&quot;, MDGroup , &quot;base&quot;)<br/>    arrMDGroupMember = ldapquery(&quot;(objectclass=group)&quot;, &quot;member&quot;, &quot;CN=MD_Notes,ou=md,ou=groups,ou=myou,dc=mydc&quot;, &quot;base&quot;)<br/>    For Each xyz In arrMDGroupMember<br/>       Logline xyz<br/>    Next   <br/> <br/>    Logline &quot;Found MD_-Group: &quot; &amp; MDGroup<br/>    <br/>    ' strip out logical parent folder name(s)<br/>    temp1_strippedCN = Split(MDGroup,&quot;,&quot;)<br/>    temp2_strippedCN = Split(temp1_strippedCN(0),&quot;=&quot;)<br/>    strippedCN = Mid(temp2_strippedCN(1),4)<br/>    <br/>    ' find groups md_xxx is made for (xxx &amp; cebra_xxx - groups)<br/>    arrLogicalParentGroups = ldapquery(&quot;(&amp;(objectclass=group)(|(cn=&quot; &amp; strippedCN &amp; &quot;)(cn=CEBRA_&quot; &amp; strippedCN &amp; &quot;)))&quot;, &quot;distinguishedname&quot;, &quot;ou=groups,ou=bank09916,dc=m09916&quot;, &quot;subtree&quot;)<br/>    <br/>    Dim ParentGroup<br/>    For Each ParentGroup In arrLogicalParentGroups<br/>       Logline ParentGroup<br/>    Next<br/>    <br/> Next  <br/> <br/> WScript.Echo &quot;Completed - &quot; &amp; MyTask<br/> Logline &quot;Completed - &quot; &amp; MyTask<br/> LogHeader<br/> <br/> WScript.quit<br/> 'End of Program<br/> <br/> '----------------------------------------------------------------------------<br/> Sub Logline(LineText)<br/>  Dim fso, tf<br/>  Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)<br/>  Set tf = fso.OpenTextFile(Logfile,8,true)<br/>  tf.WriteBlankLines(1)<br/>  tf.writeLine(&quot;***&quot; &amp; MyName &amp; &quot; = &quot; &amp; LineText )<br/>  tf.close()<br/> End Sub<br/> '----------------------------------------------------------------------------<br/> Sub LogLin1(LineText)<br/>  Dim fso, tf<br/>  Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)<br/>  Set tf = fso.OpenTextFile(Logfile,8,true)<br/>  tf.writeLine(String(LEN(MyName)+6,&quot; &quot;) &amp;  LineText )<br/>  tf.close()<br/> End Sub<br/> '----------------------------------------------------------------------------<br/> Sub LogHeader()<br/>  Dim fso, tf<br/>  Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)<br/>  Set tf = fso.OpenTextFile(Logfile,8,true)<br/>  tf.WriteBlankLines(1)<br/>  tf.writeLine(String(50,&quot;=&quot;) &amp; &quot; &quot; &amp; Date &amp; &quot; &quot; &amp; Time &amp; &quot; &quot; &amp; String(8,&quot;=&quot;) )<br/>  tf.close()<br/> End Sub<br/> '----------------------------------------------------------------------------<br/> Function FileExists(File)<br/>   DIM feo<br/>   Set feo = CreateObject(&quot;Scripting.FileSystemObject&quot;)<br/>   FileExists=feo.FileExists(File)<br/> End Function<br/> '----------------------------------------------------------------------------<br/> Function FolderExists(Folder)<br/>   DIM feo<br/>   Set feo = CreateObject(&quot;Scripting.FileSystemObject&quot;)<br/>   FolderExists=feo.FolderExists(Folder)<br/> End Function<br/> '----------------------------------------------------------------------------<br/> ' generic function for doing a search in AD via ldap and generate list with attribute_to_return values of all found objects , <br/> <br/> ' syntax: <br/> ' searchfilter          = ldap-compliant (&amp;(objectlass=inetorgperson)(userprincipalname=rsmi014)) - use adsiedit.msc to find out the name of the attribute of interest<br/> ' attribute_to_return   = use adsiedit.msc to find out the name of the attribute of interest, only one can be defined (for use in a one-dimensional array)<br/> ' searchbase            = base-object from where to start the query, cn=ich,ou=users,ou=..... <br/> ' scope                 = either one: base (the base-object given itself is searched) , onelevel (search amongst siblings of the provided base-object), subtree (search all objects below base-object)<br/> <br/> ' see: http://support.microsoft.com/kb/187529<br/> <br/> Function ldapquery(searchfilter,attribute_to_return,searchbase,scope)<br/> <br/>    Dim objConnection, objCommand, UserDomain, Wshshell, objRecordSet, strResults<br/> <br/>    Set Wshshell = CreateObject(&quot;WScript.Shell&quot;)<br/>    strResults = &quot;&quot;<br/>    UserDomain = WshShell.ExpandEnvironmentStrings(&quot;%USERDOMAIN%&quot;)<br/> <br/>    Set objConnection = CreateObject(&quot;ADODB.Connection&quot;)<br/>    Set objCommand = CreateObject(&quot;ADODB.Command&quot;)<br/>    objConnection.Provider = &quot;ADsDSOObject&quot;<br/>    objConnection.Open &quot;Active Directory Provider&quot;<br/> <br/>    Set objCOmmand.ActiveConnection = objConnection<br/>    objCommand.CommandText = &quot;&lt;LDAP://&quot; &amp; UserDomain &amp; &quot;/&quot; &amp; searchbase &amp; &quot;&gt;;&quot; &amp; searchfilter &amp; &quot;;&quot; &amp; attribute_to_return &amp; &quot;;&quot; &amp; scope<br/>    objCommand.Properties(&quot;Page Size&quot;) = 2000<br/>    Set objRecordSet = objCommand.Execute<br/>    <br/>    Do Until objRecordSet.EOF<br/>       If strResults = &quot;&quot; Then<br/>          strResults = objRecordSet.Fields(attribute_to_return).Value '!schreib den aktuellen Wert des Felds &quot;Name&quot; rein<br/>       Else<br/>          strResults = strResults &amp; &quot;::&quot; &amp; objRecordSet.Fields(attribute_to_return).Value '!schreib den aktuellen Wert des Felds &quot;Name&quot; rein<br/>       End If<br/>       objRecordSet.MoveNext<br/>    Loop<br/> <br/>    ldapquery = Split(strResults, &quot;::&quot;)<br/> <br/>    objConnection.Close<br/>    Set objConnection = Nothing <br/>    Set objCommand = Nothing <br/>    Set objRecordSet = Nothing <br/>    <br/> End Function<br/> '----------------------------------------------------------------------------Wed, 01 Jul 2009 16:47:34 Z2009-07-01T16:47:34Zhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/76e44e9e-e42c-4ba1-be47-b0f304acbdbf#cbfa7a34-d9b1-4c84-9f8e-84c9ce6fabb7http://social.technet.microsoft.com/Forums/en/ITCG/thread/76e44e9e-e42c-4ba1-be47-b0f304acbdbf#cbfa7a34-d9b1-4c84-9f8e-84c9ce6fabb7AssafMhttp://social.technet.microsoft.com/Profile/en-US/?user=AssafMvbscript: adsi: ldap: type mismatch with looking for members of specific groupHi, <div><br/></div> <div>The Script looks OK - I havent tested it.</div> <div>But here is a Script that does a simillar job, you can use it as referance</div> <div><br/></div> <div><a href="http://assaf.miron.googlepages.com/listusersingroup">http://assaf.miron.googlepages.com/listusersingroup</a></div> <div><br/></div> <div>Hope it helps.</div><hr class="sig">Assaf Miron <a>http://Assaf.Miron.googlepages.com</a>Thu, 02 Jul 2009 08:01:00 Z2009-07-02T08:01:00Zhttp://social.technet.microsoft.com/Forums/en/ITCG/thread/76e44e9e-e42c-4ba1-be47-b0f304acbdbf#f5dee48d-8197-49fc-a21b-a3f732f65ec5http://social.technet.microsoft.com/Forums/en/ITCG/thread/76e44e9e-e42c-4ba1-be47-b0f304acbdbf#f5dee48d-8197-49fc-a21b-a3f732f65ec5FlorianZhttp://social.technet.microsoft.com/Profile/en-US/?user=FlorianZvbscript: adsi: ldap: type mismatch with looking for members of specific groupthanks for your answer. i tried it via ldap because i is more familiar to me - if someone could explain why this line: ldapquery = Split(strResults, &quot;::&quot;) (&gt; at the end of the last function) does not result in an array the second time the script is looking for the value of the member-attribute (which is multivalued, which is a difference to the first lookup). if i´d knew how to: <br/> <br/> - get all members in an array<br/> or<br/> - get all members in an array with the in-between-step of a split-operation<br/> <br/> <br/> i´d get along.<br/> <br/> thanks<br/> <br/> <br/>Thu, 02 Jul 2009 14:22:23 Z2009-07-02T14:22:23Z