none
Add Multiple MAC Accounts At Once VBScript RRS feed

  • Question

  • Hello.  I'm trying to implement 802.1x on our LAN and would like to build upon a script I was provided which only allows one MAC address to be input at a time and added to a already created Active Directory group.  I was wondering how would I modify the below to read from a text file or csv file with multiple MACs and add to a selected group in Active Directory?  Thanks.


    ' This subroutine Creates a MAC account in AD and adds it to the specified VLAN Group
    Sub AddMAC
       Mname = inputbox("Enter the MAC xxxxxxxxxxxx", "Create MAC/VLAN Account")
    ' Remove capital letters, special characters, and empty space
       Mname = LCase(Mname)
       Mname = trim (Mname)
       Mname = Replace(Mname, Chr(34), "")
       Mname = Replace(Mname, Chr(39), "")
       Mname = Replace(Mname, "!", "")
       Mname = Replace(Mname, "@", "")
       Mname = Replace(Mname, "#", "")
       Mname = Replace(Mname, "$", "")
       Mname = Replace(Mname, "%", "")
       Mname = Replace(Mname, "^", "")
       Mname = Replace(Mname, "&", "")
       Mname = Replace(Mname, "*", "")
       Mname = Replace(Mname, "(", "")
       Mname = Replace(Mname, ")", "")
       Mname = Replace(Mname, "_", "")
       Mname = Replace(Mname, "+", "")
       Mname = Replace(Mname, "~", "")
       Mname = Replace(Mname, "`", "")
       Mname = Replace(Mname, "-", "")
       Mname = Replace(Mname, "=", "")
       Mname = Replace(Mname, "[", "")
       Mname = Replace(Mname, "]", "")
       Mname = Replace(Mname, "{", "")
       Mname = Replace(Mname, "}", "")
       Mname = Replace(Mname, "\", "")
       Mname = Replace(Mname, "|", "")
       Mname = Replace(Mname, ";", "")
       Mname = Replace(Mname, ":", "")
       Mname = Replace(Mname, "/", "")
       Mname = Replace(Mname, "?", "")
       Mname = Replace(Mname, ">", "")
       Mname = Replace(Mname, ",", "")
       Mname = Replace(Mname, "<", "")
       Mname = Replace(Mname, "g", "")
       Mname = Replace(Mname, "h", "")
       Mname = Replace(Mname, "i", "")
       Mname = Replace(Mname, "j", "")
       Mname = Replace(Mname, "k", "")
       Mname = Replace(Mname, "l", "")
       Mname = Replace(Mname, "m", "")
       Mname = Replace(Mname, "n", "")
       Mname = Replace(Mname, "o", "")
       Mname = Replace(Mname, "p", "")
       Mname = Replace(Mname, "q", "")
       Mname = Replace(Mname, "r", "")
       Mname = Replace(Mname, "s", "")
       Mname = Replace(Mname, "t", "")
       Mname = Replace(Mname, "u", "")
       Mname = Replace(Mname, "v", "")
       Mname = Replace(Mname, "w", "")
       Mname = Replace(Mname, "x", "")
       Mname = Replace(Mname, "y", "")
       Mname = Replace(Mname, "z", "")
       Mname = Replace(Mname, " ", "")
       Mname = Replace(Mname, ".", "")

    ' Verify that the MAC address is 12 digits
    If NOT Len(Mname)=12 then
      MsgBox "Invalid MAC Address!"
    Else
      On Error Resume Next
      Vlan = inputbox("Enter VLAN ID for Device: ", "Enter VLAN Information")
     Set objGroup = GetObject("LDAP://" & VlanGroup & Vlan & ",")
      If Err.Number <> 0 then
          MsgBox "VLAN " & VLan & " Group Does Not Exist!"
      Else
      set objCont = GetObject("LDAP://" & VlanGroup)
      set objComp = objCont.Create("computer", "cn=" & Mname)
    '  This sets the account name
      objComp.Put "sAMAccountName", Mname
    '  This sets the account description
      objComp.Put "description", Desc
    '  This sets the account type to Normal and sets the Password to Never expire
      objComp.Put "userAccountControl", "66080"
      objComp.SetInfo()
      objComp.SetPassword (Password)
    '  objComp.AccountDisabled = False
      objComp.SetInfo()
             objGroup.Add(objComp.ADsPath)
      MsgBox "Account: " & Mname & " added to VLAN " & Vlan
      End if
    End if
    End Sub

    • Moved by Bill_Stewart Wednesday, September 4, 2019 9:25 PM This is not "scripts on demand"
    Monday, April 22, 2019 6:49 PM