ISG_Query
asked on
Please help with this vb script ?
Hi All-knowing ones !
Please could you help point out where I am going wrong ? My script is tasked with pulling out the list of users and groups who are authorised to send to a distribution list. As it is below, it only pulls out groups or dist-lists which are listed in the tab and NOT the users. How do I modify it to pull the users as well ?
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ------
Set objShell = CreateObject("Wscript.Shel l")
Set objFS = CreateObject("Scripting.Fi leSystemOb ject")
'*** Ask for username
strUser = Inputbox("Please enter the name of the Distribution List you wish to view.")
If strUser = "" then
Msgbox "No UserID entered! Script will now exit."
WScript.Quit
End If
'*** Declare variables and constants
Dim con
Dim rs
Dim Com
Dim objDataScript
Const DATA_FOLDER = "C:\Scripts"
Const DATA_SCRIPT = "C:\Scripts\AD Dist List Membership results.txt"
GetADUserDetails = 0
'*** Setup an ADO query to get the values from the target object.
Set con = CreateObject("ADODB.Connec tion")
Set rs = CreateObject("ADODB.Record set")
Set Com = CreateObject("ADODB.Comman d")
'*** Open a Connection object.
con.Provider = "ADsDSOObject"
con.Open "Active Directory Provider"
'*** Create a command object on this connection.
Set Com.ActiveConnection = con
'*** Collect ADsPath, sAMAccountName and cn details for target object
Com.CommandText = "<LDAP://invicta.cantium.n et>;(samAc countName= " & strUser & ");ADsPath,sAMAccountName, cn"
'*** Set the preferences for Search.
Com.Properties("Page Size") = 1000
Com.Properties("Timeout") = 30
'*** Execute the query.
Set rs = Com.Execute
If rs.RecordCount = 1 Then
strPath = rs.Fields(0).Value '*** Store path to users account
Else
GetADUserDetails = 1 '*** User not found
End If
If GetADUserDetails = 1 then
Msgbox "Folder name entered not found in directory."
WScript.Quit
Else '*** User exists so continue
If Not objFS.FolderExists(DATA_FO LDER) Then '*** Check for folder existence, if not found then create
Set objFolder = objFS.CreateFolder(DATA_FO LDER)
End If
If objFS.FileExists(DATA_SCRI PT) Then '*** File exists so append information to it
On Error Resume Next
Set objDataScript = objFS.OpenTextFile(DATA_SC RIPT,8,Tru e)
objDataScript.WriteBlankLi nes (1)
objDataScript.WriteLine "************************* *********"
objDataScript.WriteLine "* " & strUser
objDataScript.WriteLine "************************* *********"
Set objUser = GetObject(strPath)
arrMemberOf = objUser.GetEx("dLMemSubmit Perms")
For Each Group in arrMemberOf
Set objGroup = GetObject("LDAP://" & Group)
GroupCN = objGroup.CN
objDataScript.WriteLine ""& GroupCN
Next
objDataScript.Close
MsgBox "Finished!"
Else
Set objDataScript = objFS.CreateTextFile(DATA_ SCRIPT,Tru e) '*** File does not exist so create and then write to it
On Error Resume Next
Set objDataScript = objFS.OpenTextFile(DATA_SC RIPT,True)
objDataScript.WriteLine "************************* *********"
objDataScript.WriteLine "* " & strUser
objDataScript.WriteLine "************************* *********"
Set objUser = GetObject(strPath)
arrMemberOf = objUser.GetEx("dLMemSubmit Perms") '*** Get users group membership
For Each Group in arrMemberOf '*** Loop through groups
Set objGroup = GetObject("LDAP://" & Group)
'*** Check group is dist type or universal sec group
GroupCN = objGroup.CN '*** Get group name
objDataScript.WriteLine ""& GroupCN '*** Write group name
Next
objDataScript.Close
MsgBox "Finished!" '*** Indicate completion of process
End If
End If
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------
The list I wish to extract is under the Exchange General tab, and is the list under the Message Rectrictions section. Do I need to modify the "dLMemSubmitPerms" object name ?
Many thanks
Please could you help point out where I am going wrong ? My script is tasked with pulling out the list of users and groups who are authorised to send to a distribution list. As it is below, it only pulls out groups or dist-lists which are listed in the tab and NOT the users. How do I modify it to pull the users as well ?
--------------------------
Set objShell = CreateObject("Wscript.Shel
Set objFS = CreateObject("Scripting.Fi
'*** Ask for username
strUser = Inputbox("Please enter the name of the Distribution List you wish to view.")
If strUser = "" then
Msgbox "No UserID entered! Script will now exit."
WScript.Quit
End If
'*** Declare variables and constants
Dim con
Dim rs
Dim Com
Dim objDataScript
Const DATA_FOLDER = "C:\Scripts"
Const DATA_SCRIPT = "C:\Scripts\AD Dist List Membership results.txt"
GetADUserDetails = 0
'*** Setup an ADO query to get the values from the target object.
Set con = CreateObject("ADODB.Connec
Set rs = CreateObject("ADODB.Record
Set Com = CreateObject("ADODB.Comman
'*** Open a Connection object.
con.Provider = "ADsDSOObject"
con.Open "Active Directory Provider"
'*** Create a command object on this connection.
Set Com.ActiveConnection = con
'*** Collect ADsPath, sAMAccountName and cn details for target object
Com.CommandText = "<LDAP://invicta.cantium.n
'*** Set the preferences for Search.
Com.Properties("Page Size") = 1000
Com.Properties("Timeout") = 30
'*** Execute the query.
Set rs = Com.Execute
If rs.RecordCount = 1 Then
strPath = rs.Fields(0).Value '*** Store path to users account
Else
GetADUserDetails = 1 '*** User not found
End If
If GetADUserDetails = 1 then
Msgbox "Folder name entered not found in directory."
WScript.Quit
Else '*** User exists so continue
If Not objFS.FolderExists(DATA_FO
Set objFolder = objFS.CreateFolder(DATA_FO
End If
If objFS.FileExists(DATA_SCRI
On Error Resume Next
Set objDataScript = objFS.OpenTextFile(DATA_SC
objDataScript.WriteBlankLi
objDataScript.WriteLine "*************************
objDataScript.WriteLine "* " & strUser
objDataScript.WriteLine "*************************
Set objUser = GetObject(strPath)
arrMemberOf = objUser.GetEx("dLMemSubmit
For Each Group in arrMemberOf
Set objGroup = GetObject("LDAP://" & Group)
GroupCN = objGroup.CN
objDataScript.WriteLine ""& GroupCN
Next
objDataScript.Close
MsgBox "Finished!"
Else
Set objDataScript = objFS.CreateTextFile(DATA_
On Error Resume Next
Set objDataScript = objFS.OpenTextFile(DATA_SC
objDataScript.WriteLine "*************************
objDataScript.WriteLine "* " & strUser
objDataScript.WriteLine "*************************
Set objUser = GetObject(strPath)
arrMemberOf = objUser.GetEx("dLMemSubmit
For Each Group in arrMemberOf '*** Loop through groups
Set objGroup = GetObject("LDAP://" & Group)
'*** Check group is dist type or universal sec group
GroupCN = objGroup.CN '*** Get group name
objDataScript.WriteLine ""& GroupCN '*** Write group name
Next
objDataScript.Close
MsgBox "Finished!" '*** Indicate completion of process
End If
End If
--------------------------
The list I wish to extract is under the Exchange General tab, and is the list under the Message Rectrictions section. Do I need to modify the "dLMemSubmitPerms" object name ?
Many thanks
ASKER
Hey Rob
Thanks for the suggestion. I tried it a few times, but it ends up pulling a whole lot of other names. I will try it once or twice more and see.
First impressions say it doesn't work as required.
Thanks for the suggestion. I tried it a few times, but it ends up pulling a whole lot of other names. I will try it once or twice more and see.
First impressions say it doesn't work as required.
Well what that block should do, is pull the group members of each group out....is that what you were after?
Rob.
Rob.
ASKER
Hey. No, what I'm looking to do, is pull a list of the people or groups, that are listed in the "Only from / From everyone except" field, on the "Exchange General" tab.
Basically I need to record who can (or can't) send to a dist list.
The script I pasted above in my question, only returns the names of groups, which are listed in this field, NOT individuals who are listed.
Thanks
Basically I need to record who can (or can't) send to a dist list.
The script I pasted above in my question, only returns the names of groups, which are listed in this field, NOT individuals who are listed.
Thanks
ASKER
Any other ideas, oh all-knowing ones ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Apologies all powerful ones - time ran away with me.
Your response was very helpful, thank you. I will put it into practise ASAP.
Your response was very helpful, thank you. I will put it into practise ASAP.
ASKER
Many thanks for a great forum and superb expert knowledge !
For Each objMember In objGroup.Members
objDataScript.WriteLine objMember.CN
Next
Under the two instances of this line:
objDataScript.WriteLine ""& GroupCN
Regards,
Rob.