Link to home
Start Free TrialLog in
Avatar of ISG_Query
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.Shell")
Set objFS = CreateObject("Scripting.FileSystemObject")

'*** 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.Connection")
Set rs = CreateObject("ADODB.Recordset")
Set Com = CreateObject("ADODB.Command")

'*** 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.net>;(samAccountName=" & 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_FOLDER) Then            '*** Check for folder existence, if not found then create
            Set objFolder = objFS.CreateFolder(DATA_FOLDER)
      End If
      
      If objFS.FileExists(DATA_SCRIPT) Then      '*** File exists so append information to it
            On Error Resume Next
            Set objDataScript = objFS.OpenTextFile(DATA_SCRIPT,8,True)
            objDataScript.WriteBlankLines (1)
            objDataScript.WriteLine "**********************************"
            objDataScript.WriteLine "*            " & strUser
            objDataScript.WriteLine "**********************************"
            Set objUser = GetObject(strPath)

            arrMemberOf = objUser.GetEx("dLMemSubmitPerms")
            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,True)      '*** File does not exist so create and then write to it
            On Error Resume Next
            Set objDataScript = objFS.OpenTextFile(DATA_SCRIPT,True)
            objDataScript.WriteLine "**********************************"
            objDataScript.WriteLine "*            " & strUser
            objDataScript.WriteLine "**********************************"
            Set objUser = GetObject(strPath)

            arrMemberOf = objUser.GetEx("dLMemSubmitPerms")            '*** 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

Avatar of RobSampson
RobSampson
Flag of Australia image

Hi, try adding this
                For Each objMember In objGroup.Members
                      objDataScript.WriteLine objMember.CN
                Next

Under the two instances of this line:
          objDataScript.WriteLine ""& GroupCN    

Regards,

Rob.
Avatar of ISG_Query
ISG_Query

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.
Well what that block should do, is pull the group members of each group out....is that what you were after?

Rob.
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
Any other ideas, oh all-knowing ones ?
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Apologies all powerful ones - time ran away with me.

Your response was very helpful, thank you. I will put it into practise ASAP.
Many thanks for a great forum and superb expert knowledge !