Prev: Split Method
Next: How to check a AD user's password
From: Dan on 22 Mar 2010 19:46 Hey all, I'm trying to get split to get all the parameters minus one (the first one). For example: I get all the parameters needed with this: NewGroup = Split(OldGroup,",", -1) Then I create an Input box and try to get all of the members of the new array (minus the first one) like this: objOU=InputBox("Enter the DN of the OU:", "Select OU", groupname2(1 & 2 & 3)) Now, I know this has several issues. First and foremost it doesn't work and second I don't know how many other elements I'm going to have. Is there a way to loop through the remaining items to get them all in the new input box? Thanks for any help!
From: Al Dunbar on 22 Mar 2010 22:01 "Dan" <Dan(a)discussions.microsoft.com> wrote in message news:86D2C999-46FC-49ED-8DCE-BC34746436FA(a)microsoft.com... > Hey all, > I'm trying to get split to get all the parameters minus one (the first > one). For example: > > I get all the parameters needed with this: > > NewGroup = Split(OldGroup,",", -1) > > Then I create an Input box and try to get all of the members of the new > array (minus the first one) like this: > > objOU=InputBox("Enter the DN of the OU:", "Select OU", groupname2(1 & 2 & > 3)) > > Now, I know this has several issues. First and foremost it doesn't work > and > second I don't know how many other elements I'm going to have. Is there a > way to loop through the remaining items to get them all in the new input > box? Seems a bit vague to me. if Oldgroup contained, say, "one,two,three", then, newgroup will contain array("one","two","three"). Then you want to do what with two and three? Anyway, to loop through all but the first element of an array can be done like this first = true for each item in newgroup if true then first = false else wscript.echo item end if next Not sure what you mean about "getting them all in the inputbox". Inputbox is for input, so what goes into that inputbox is what you type into it. If you want to input more than one item, you could enter a series of items separated by a delimiter and then use split to extract them. If you want to input your n minus one items, using the elements of the newgroup array in the prompt parameter, adapt my code above. If oldgroup itself is a DN, and you are trying to split that into separate elements, you would be better off calling adsi methods to determine the parent OU of a group, as the comma might actually appear in the name of one of the OU's in the path. /Al
From: Richard Mueller [MVP] on 22 Mar 2010 22:06 "Dan" <Dan(a)discussions.microsoft.com> wrote in message news:86D2C999-46FC-49ED-8DCE-BC34746436FA(a)microsoft.com... > Hey all, > I'm trying to get split to get all the parameters minus one (the first > one). For example: > > I get all the parameters needed with this: > > NewGroup = Split(OldGroup,",", -1) > > Then I create an Input box and try to get all of the members of the new > array (minus the first one) like this: > > objOU=InputBox("Enter the DN of the OU:", "Select OU", groupname2(1 & 2 & > 3)) > > Now, I know this has several issues. First and foremost it doesn't work > and > second I don't know how many other elements I'm going to have. Is there a > way to loop through the remaining items to get them all in the new input > box? > > Thanks for any help! You would need to loop through the array. The first element would have index 0, which is the element you want to skip. The UBound function would return the maximum index. For example: ======= NewGroup = Split(oldGroup, ",") GroupNames = "" For k = 1 To UBound(NewGroup) If GroupNames "") Then GroupNames = NewGroup(k) Else GroupNames = GroupNames & "," & NewGroup(k) End If Next objOU=InputBox("Enter the DN of the OU:", "Select OU", GroupNames) ========= However, I'm guessing that the value of oldGroup is the Distinguished Name (DN) of an object, and you want the DN of it's parent container/OU. If so, the code above will fail if the Relative Distinguished Name of the object (the Common Name if the object is a user or group or computer) has an embedded comma. For example, the DN could be: cn=Smith, James,ou=West,dc=MyDomain,dc=com There are ways to reliably parse this, but the best method is to bind to the object and use the Parent method to retrieve the ADsPath of the parent container or OU. The ADsPath will be the DN with the string "LDAP://" prepended. For example: ' Assuming the value of oldGroup is the DN of a group object. ' Bind to the object. Set objGroup = GetObject("LDAP://" & oldGroup) ' Retrieve ADsPath of parent OU. strParentADsPath = objGroup.Parent ' Remove LDAP:// moniker to get DN of parent OU. strParentDN = Mid(strParentADsPath, 8) strOU = InputBox("Enter the DN of the OU:", "Select OU", strParentDN) -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net --
From: Dan on 23 Mar 2010 12:54 Hey Al, Yes, the value would be "one,two,three" or something like that and I'd like the default value of the new input box to be just "two,three". Thanks! "Al Dunbar" wrote: > > > "Dan" <Dan(a)discussions.microsoft.com> wrote in message > news:86D2C999-46FC-49ED-8DCE-BC34746436FA(a)microsoft.com... > > Hey all, > > I'm trying to get split to get all the parameters minus one (the first > > one). For example: > > > > I get all the parameters needed with this: > > > > NewGroup = Split(OldGroup,",", -1) > > > > Then I create an Input box and try to get all of the members of the new > > array (minus the first one) like this: > > > > objOU=InputBox("Enter the DN of the OU:", "Select OU", groupname2(1 & 2 & > > 3)) > > > > Now, I know this has several issues. First and foremost it doesn't work > > and > > second I don't know how many other elements I'm going to have. Is there a > > way to loop through the remaining items to get them all in the new input > > box? > > Seems a bit vague to me. if Oldgroup contained, say, "one,two,three", then, > newgroup will contain array("one","two","three"). Then you want to do what > with two and three? > > Anyway, to loop through all but the first element of an array can be done > like this > > first = true > for each item in newgroup > if true then > first = false > else > wscript.echo item > end if > next > > Not sure what you mean about "getting them all in the inputbox". Inputbox is > for input, so what goes into that inputbox is what you type into it. If you > want to input more than one item, you could enter a series of items > separated by a delimiter and then use split to extract them. If you want to > input your n minus one items, using the elements of the newgroup array in > the prompt parameter, adapt my code above. If oldgroup itself is a DN, and > you are trying to split that into separate elements, you would be better off > calling adsi methods to determine the parent OU of a group, as the comma > might actually appear in the name of one of the OU's in the path. > > /Al > >
From: Tom Lavedas on 23 Mar 2010 13:21
On Mar 23, 12:54 pm, Dan <D...(a)discussions.microsoft.com> wrote: > Hey Al, > Yes, the value would be "one,two,three" or something like that and I'd > like the default value of the new input box to be just "two,three". > Thanks! > I use something like this to remove the first item in a comma delimited list ... sText = "one,two,three" ' for example aItems = Split(sText, ",") aItems(0) = "" sText = Mid(Join(aItems, ","), 2) ' less the first item _____________________ Tom Lavedas |