Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Bit lost in an array

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,49224
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Bit lost in an array
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Bit lost in an array - 7/9/2007 9:46:54 PM   
  stubar

 

Posts: 50
Score: 0
Joined: 7/14/2005
Status: offline
Hello, wonder if anyone can help?
I've written this to get members from a group and it works fine. Eventualy it will read from a list of groups and give me all the users. However .... I can get the full path of each user in question but all i want is the sAMAccountName or CN. As the subject says .... :o)

Thanks in advance for your help.


dim input, path
' stuart_test_group
input = inputbox("Enter group name")
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")
wscript.echo(strDNSDomain)
Set objDomain = GetObject("LDAP://" & strDNSDomain)
path = ("LDAP://server/cn=" & input & "," & strDNSDomain)
wscript.echo(path)
'
Set objGroup = GetObject (Path)
objGroup.GetInfo
arrMemberOf = objGroup.GetEx("member")
For Each strMember in arrMemberOf
   WScript.echo strMember

Next
wscript.quit
 
 
Post #: 1
 
 RE: Bit lost in an array - 7/9/2007 10:15:36 PM   
  Parabellum


Posts: 222
Score: 0
Joined: 11/12/2006
From: UK
Status: offline
Have you tried this....
don't have any means to test at the moment... but it should work?
 
Set objGroup = GetObject (Path)
objGroup.GetInfo
arrMemberOf = objGroup.GetEx("member")
For Each strMember in arrMemberOf 
   strSAM = strMember.sAMAccountName
  WScript.echo strMember 
  WScript.echo strSAM
Next

(in reply to stubar)
 
 
Post #: 2
 
 RE: Bit lost in an array - 7/10/2007 12:13:06 AM   
  stubar

 

Posts: 50
Score: 0
Joined: 7/14/2005
Status: offline
Thanks for that, but I'm getting error 800a01a8.

I've defined the variable and added option explicit to see if thats pulls it out but no joy.

Any ideas?

(in reply to stubar)
 
 
Post #: 3
 
 RE: Bit lost in an array - 7/10/2007 1:00:50 AM   
  dm_4ever


Posts: 2664
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
If the path is correct...remove the parentheses:

path = ("LDAP://server/cn=" & input & "," & strDNSDomain)

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to stubar)
 
 
Post #: 4
 
 RE: Bit lost in an array - 7/10/2007 1:14:46 AM   
  stubar

 

Posts: 50
Score: 0
Joined: 7/14/2005
Status: offline
 

path = "LDAP://server/cn=" & input & "," & strDNSDomain
wscript.echo(path)
'
Set objGroup = GetObject (Path)
objGroup.GetInfo
arrMemberOf = objGroup.GetEx("member")
For Each strMember in arrMemberOf 
  strSAM = strMember.sAMAccountName
WScript.echo strMember 
WScript.echo strSAM

Error message is
Error Object required: 'CN=stuartBarnett - '
Code: 800A01A8

Stuart Barnett - Me is the CN name of the first member of the group and was originaly returned. It just doesn't seem to be able to to take the strmember name from the array and return the samaccountname. Fiddlesticks!

(in reply to dm_4ever)
 
 
Post #: 5
 
 RE: Bit lost in an array - 7/10/2007 1:18:50 AM   
  dm_4ever


Posts: 2664
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
You should check the exact value for your distinguished path...best way is to look at ADSI or look in "Post a VBScript" for the AD Query templates to search for you.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to stubar)
 
 
Post #: 6
 
 RE: Bit lost in an array - 7/10/2007 1:29:54 AM   
  stubar

 

Posts: 50
Score: 0
Joined: 7/14/2005
Status: offline
Thanks for getting back so quickly.
I've checked with adsiEdit and the path is correct. As you can see with the original it outputs to a msgbox and the original script works and does what is required, it just seems to be the line:
strSAM = strMember.sAMAccountName
in the newer version.

Having looked around other scripts common sense says this should be the way to do it, ...... but it's not for some reason.
As a complete novice I would say that what I've got gets the full full path of the users including the CN and the OU but cannot make the leap between CN and SamAccountName, does that sound about right?

(in reply to dm_4ever)
 
 
Post #: 7
 
 RE: Bit lost in an array - 7/10/2007 6:23:31 AM   
  mcds99


Posts: 434
Score: 4
Joined: 2/28/2006
Status: online
Try this
newStrSam = strSam

wscript.echo newStrSam

Sometimes you must copy the data in to another variable before it will display, I don't know why this happens.

_____________________________

Sam

Keep it Simple Make it Fun KiSMiF

(in reply to stubar)
 
 
Post #: 8
 
 RE: Bit lost in an array - 7/10/2007 8:51:18 PM   
  stubar

 

Posts: 50
Score: 0
Joined: 7/14/2005
Status: offline
Nope still no joy.

It seems it wants the strMember to be set as an object.

What is truly defeating me is that it works the one way but not the other.

(in reply to mcds99)
 
 
Post #: 9
 
 RE: Bit lost in an array - 7/10/2007 11:56:15 PM   
  stubar

 

Posts: 50
Score: 0
Joined: 7/14/2005
Status: offline
Thanks everyone, all done for now.
I had to re-set the LDAP path to look at the user and not the group (or something like that :o)
-----------------------------------------------------------------------------------------------------------------
const ForReading = 1
const ForWriting = 2
const ForAppending = 8
set fso = CreateObject("Scripting.FileSystemObject")
' set users = fso.OpenTextFile("groups.txt")
set logfile = fso.OpenTextFile("Logfile.txt", ForAppending)
input = inputbox("Enter group name")
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")
        '  wscript.echo(strDNSDomain)
Set objDomain = GetObject("LDAP://" & strDNSDomain)
   path = "LDAP://server/cn=" & input & "," & strDNSDomain
       '   wscript.echo(path)
'
Set objRootDSE = nothing
Set objDomain = nothing
Set objGroup = GetObject (Path)
objGroup.GetInfo

 arrMemberOf = objGroup.GetEx("member")
 For Each strMember in arrMemberOf
    ' WScript.echo strMember

 strUser = Mid(strMember, 4, 330)
 arrUser = Split(strMember, "," )
  ' Wscript.Echo arrUser(0)
 Dim delmem
 delmem = replace(arrUser(0), "CN=", "")
' wscript.echo(delmem)
'-----------------------------------------------------------------
    Set objUser = GetObject("LDAP://" & strMember)
    path2 = ("
LDAP://server/" & strMember)
   ' wscript.echo("This is path2 " & path2)
 strsam = objUser.get("samaccountname")
       Set objUser = nothing

'-----------------------------------------------------------------
logfile.writeline(strsam & " ~ " & delmem)
   
Set strMember = Nothing
Next
wscript.echo("Complete. Check the logfile")

(in reply to stubar)
 
 
Post #: 10
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Bit lost in an array Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts