Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27416

Extreme beginner in VB

$
0
0
Hello all,

First time poster, a little background on me, I just started my first IT job, graduated with a programming degree but never was taught VB. I am currently in the learning phase at my job and haven't been busy really. I let my boss know that I could use more work and he gave me a little assignment.

He wants me to take a VBS file that takes all the names and emails of everyone in the company from our AD and put it in a CSV file. What he wants me to do is:

1) Make it a .net file so it can be executable and be placed on employees desktps.
2) Create a progress bar to show how its going. (As of know when you exe it nothing appears until a box pops up saying completed)
3) Clean up the data produced.(ie. If someones name is John Smith Jr. then Jr is placed in the email column and the email is pushed over a column)

Any help would greatly be appriciated =D heres the code:

Code:

' VBScript Source File
'
' NAME: LISTPROXYADDRESSES.VBS
' VERSION: 1.1
' AUTHOR: Bharat Suneja , Bharat Suneja  --> Modified By: Kevin Reed
' CREATE DATE  : 5/06/2004
' LAST MODIFIED : 5/19/2011
'==================================================================================================
' COMMENT:

'==================================================================================================

'Security
Dim objADSysInfo : Set objADSysInfo = CreateObject("ADSystemInfo")
Dim objUser : Set objUser = GetObject("LDAP://" & objADSysInfo.UserName)
if objUser.givenname & " " & objuser.sn <> "Jonathan Salina" Then
wscript.echo "Unauthorized User Detected!" & VbCrlf & "The Program Will Now Close"
wscript.quit
end if

'Set up constant for deleting values from multivalued attribute memberOf

Const ADS_PROPERTY_NOT_FOUND  = &h8000500D
Const ADS_UF_ACCOUNTDISABLE = 2                      'For UserAccountControl
Const strX400Search = "X400"
'______________________________________________________

'Set RootDSE
Set objRootDSE = GetObject("LDAP://rootDSE")
strDomain = objRootDSE.Get("defaultNamingContext")
strADPath = "LDAP://" & strDomain
'wscript.Echo strADPath
Set objDomain = GetObject(strADPath)
'wscript.echo "objDomain: " & objDomain.distinguishedName

'Setup ADODB connection
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 5000

'Execute search command to look for Contacts & Groups
    objCommand.CommandText = _
      "<" & strADPath & ">" & ";(&(|(objectClass=contact)(objectClass=group))(mail=*))" & ";distinguishedName,displayName,mail,proxyAddresses;subtree"

    'Execute search to get Recordset
    Set objRecordSet = objCommand.Execute
   
       
        'Start procedure
       
    'strResult = strResult & VbCrLf & "Domain: " & strDomain
'THESE ARE UNEEDED
    'strResult = strResult & VbCrlf &  "#Total Records Found (other accounts): " & objRecordSet.RecordCount & VbCrlf
    AddressCount = 0


'*************************************
'Begin second query for users
varDisabledCounter = 0                 

'Execute search command to look for user
    objCommand.CommandText = _
      "<" & strADPath & ">" & ";(&(objectClass=user)(mail=*))" & ";distinguishedName,displayName,mail,proxyAddresses;subtree"

    'Execute search to get Recordset
    Set objRecordSet = objCommand.Execute
   
   
        strResult = strResult & "Name" & "," & "Email" & VbCrLf

      While Not objRecordSet.EOF 'Iterate through the search results
            strUserDN = objRecordSet.Fields("distinguishedName")    'Get User's distinguished name from Recordset into a string
            strUserDN=Replace(strUserDN,"/","\/")
            set objUser= GetObject("LDAP://"& strUserDN & "")        'Use string to bind to user object
           
           
            If objUser.AccountDisabled = FALSE Then                    'If User account disabled, then skip         



                      strResult = strResult & objUser.givenName & " " & objUser.sn & ","
                      strResult = strResult & objUser.mail
                      'arrProxyAddresses = objRecordSet.Fields("proxyAddresses")
                      'If IsArray(objRecordSet.Fields("proxyAddresses")) Then
                      'strResult = strResult & VbCrLf & "Proxy Addresses"
                         
                          'For Each ProxyAddress in arrProxyAddresses
                            'Sub: Check X400
                            'If InStr(ProxyAddress, strX400Search) <> 0 Then
                                '        'Wscript.Echo "#This was an x400"
                                    ' Else
                                '        strResult = strResult & VbCrlf &  proxyAddress
                              '  AddressCount = AddressCount + 1
                            ' End If  'Ends loop for X400 address
                        ' Next
                          '  Else
                                '  strResult = strResult & VbCrLf &  "#Object does not have proxy addresses"
                        ' End If
                              strResult = strResult &  VbCrLf
               
          End If  'End check for disabled user
           
    objRecordSet.MoveNext
Wend  'End second query for users

             
'strResult = "Users, Groups & Contacts" & VbCrLf & "-------------------------" & VbCrLf & strResult
'strResult = strResult & VbCrLf & "Disabled Users" & VbCrLf & "-------------------------" & VbCrLf & strResult2

'Output to a text file
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Set objOutputFile = objFileSystem.CreateTextFile("C:\Email List.csv")
objOutputFile.Write strResult

LF=chr(10)
WScript.Echo "Done - Please Check C:\Email List.csv to see your file."& LF & LF & "If you have any questions please contact Kevin Reed"


Viewing all articles
Browse latest Browse all 27416

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>