Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Distrubution List Script Issue

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Distrubution List Script Issue
  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 >>
 Distrubution List Script Issue - 3/3/2008 1:11:48 AM   
  Neiluk

 

Posts: 2
Score: 0
Joined: 3/3/2008
Status: offline
Hi

New member here, and allready looking for help just started VB scripting as part of a new role and cobbled together this script from locations but i am getting a error and i cant see where i am going wrong
Error
*GBL- AIS P ROA
C:\Stuff\DL2.vbs(27, 2) Microsoft VBScript runtime error: Object required: '*GBL
- AIS P ROA'
End Error

Script
Dim objExcel
Dim iRow
Dim strUser
Dim samAccountName
Dim l
Dim sDestOU
Dim oFSO
Dim sTextLine
Dim sUserName
Dim sName
Dim DestOU
Dim managedBy
Dim objDistList
Set objDistList = GetObject("LDAP://CN=*GBL- AIS P ROA,ou=Distribution Lists,ou=AVZ Messaging,dc=corp,dc=amvescap,dc=net")
Set objExcel = CreateObject("Excel.Application")
With objExcel
.SheetsInNewWorkbook = 1
.Workbooks.Add
.Visible = True
objDistList = mid(objDistList.Name, instr(1,objDistList.Name,"=") + 1 )
If Left(strgroup,1) = "*" then objDistList = Right(objDistList,Len(objDistList)-1)
WScript.Echo objDistList

For Each strUser In objDistList.member
 WScript.Echo
   Set objUser =  GetObject("LDAP://" & strUser & samAccountName & l)
'    WScript.Echo objuser.CN
   .Cells(iRow,1) = objUser.CN
   .Cells(iRow,2) = objUser.samAccountName
   .Cells(iRow,3) = objUser.Company
   .Cells(iRow,4) = objUser.managedBy
   irow=irow + 1
Next
.Columns(1).entirecolumn.autofit
End With
Set objExcel = Nothing
Set objGroup = Nothing 

As far as i can see it is getting the object so not sure why it is saying object reuqired

Any help would be welcome

Thanks

Neil

 
 
Post #: 1
 
 RE: Distrubution List Script Issue - 3/3/2008 1:28:56 AM   
  ebgreen


Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
I'm going to go through your script. My comments are in red:

Dim objExcel
Dim iRow
Dim strUser
Dim samAccountName
Dim l
Dim sDestOU
Dim oFSO
Dim sTextLine
Dim sUserName
Dim sName
Dim DestOU
Dim managedBy
Dim objDistList
Set objDistList = GetObject("LDAP://CN=*GBL- AIS P ROA,ou=Distribution Lists,ou=AVZ Messaging,dc=corp,dc=amvescap,dc=net")
Set objExcel = CreateObject("Excel.Application")
With objExcel
.SheetsInNewWorkbook = 1
.Workbooks.Add
.Visible = True
objDistList = mid(objDistList.Name, instr(1,objDistList.Name,"=") + 1 ) You are taking objDistList which is currently an LDAP object and changing it to a string. While technically valid, you should at least use a variable name that starts with str (such as strDistListName) to avoid confusion
If Left(strgroup,1) = "*" then objDistList = Right(objDistList,Len(objDistList)-1) Here you are trying to get the left part of strGroup, but as near as I can tell you never populate strGroup with any value
WScript.Echo objDistList

For Each strUser In objDistList.member Here you are trying to accecc the .Members property of objDistList, but remember you converted that variable to a string and strings do not have a .Members collection. This is the cause of the error that you are getting. You are right that the script is getting the object, you just happen to be throwing the object away 6 lines after you get it.
WScript.Echo
  Set objUser =  GetObject("LDAP://" & strUser & samAccountName & l)
'    WScript.Echo objuser.CN
  .Cells(iRow,1) = objUser.CN
  .Cells(iRow,2) = objUser.samAccountName
  .Cells(iRow,3) = objUser.Company
  .Cells(iRow,4) = objUser.managedBy
  irow=irow + 1
Next
.Columns(1).entirecolumn.autofit
End With
Set objExcel = Nothing
Set objGroup = Nothing 

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Neiluk)
 
 
Post #: 2
 
 RE: Distrubution List Script Issue - 3/3/2008 1:56:47 AM   
  Neiluk

 

Posts: 2
Score: 0
Joined: 3/3/2008
Status: offline
Ok so if i understand you correctly,

On this bit i am changing it to a variable
objDistList = mid(objDistList.Name, instr(1,objDistList.Name,"=") + 1 ) You are taking objDistList which is currently an LDAP object and changing it to a string. While technically valid, you should at least use a variable name that starts with str (such as strDistListName) to avoid confusion

Is causing the object not found issue?
Sorry I i sound dumb ..just new to this

Thanks for your time

Neil

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: Distrubution List Script Issue - 3/3/2008 2:07:42 AM   
  ebgreen


Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
Well, first you get the LDAP object and assign it to the variable objDistList. Any time that you put a variable on the left side of an equals (except when testing a condition like in an If-Then statement) you are making an assignment. So after this line:

objDistList = mid(objDistList.Name, instr(1,objDistList.Name,"=") + 1 )

objDistList holds some LDAP object

Then after this line:

objDistList = mid(objDistList.Name, instr(1,objDistList.Name,"=") + 1 )


You have now told the variable "Don't bother holding that LDAP object anymore. Now I want you to hold this string that is a part of the LDAP object's .Name property."

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Neiluk)
 
 
Post #: 4
 
 
 
  

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 >> Distrubution List Script Issue 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