Login | |
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
| |
|
|
 |
|
 |
|
|