Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


adding user to groups

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,58681
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> adding user to groups
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 adding user to groups - 4/2/2008 2:11:39 AM   
  boston18

 

Posts: 2
Score: 0
Joined: 4/2/2008
Status: offline
Hi All,

I found and modified this script some to create AD users and with Emails In active Directory. I am needing to modify it some more to add the user created to AD groups, Ideally based upon the description of the user created. Any Ideas or Guidance would be greatly appreciated. Here is what I have thus far

Cheers


Option Explicit
Dim objRootLDAP, objContainer, objUser, objShell,objGroup
Dim objExcel, objSpread, intRow
'For Creating account attribute
Dim strUser, strOU, strSheet
Dim strCN, strSam, strFirst, strLast, strPWD, strsn, strPrincipalName, strDC1, strDC2, strCompany,strDepart
Dim strUserAcct, strDisplayName, strDescription, strDNSDomain
'for Exchange Attributes
Dim strmail, strmsExchHomeServerName,strMailAddress,strmDBUseDefaults, strmailnickname, strhomeMDB
Dim objMailbox, strproxyAddresses, strmemberOf,strGroup
strSheet = "C:\New_users.xls"
' Bind to Active Directory, Users container.
Set objRootLDAP = GetObject("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://" & strOU & _
objRootLDAP.Get("defaultNamingContext"))

' Open the Excel spreadsheet
Set objExcel = CreateObject("Excel.Application")
Set objSpread = objExcel.Workbooks.Open(strSheet)
intRow = 3 'Row 1 often contains headings, Row 2 for showing numbering
' Here is the 'DO...Loop' that cycles through the cells
' Note intRow, x must correspond to the column in strSheet
Do Until objExcel.Cells(intRow,1).Value = ""
        strSam = Trim(objExcel.Cells(intRow, 1).Value)
        strFirst = Trim(objExcel.Cells(intRow, 2).Value)
        strLast = Trim(objExcel.Cells(intRow, 3).Value)
        strDisplayName = Trim(objExcel.Cells(intRow, 4).Value)
        strCN = Trim(objExcel.Cells(intRow, 5).Value)
        strCompany = Trim(objExcel.Cells(intRow, 6).Value)        
        strUserAcct = Trim(objExcel.Cells(intRow, 7).Value)
        strPWD = Trim(objExcel.Cells(intRow, 8).Value)
        strPrincipalName = Trim(objExcel.Cells(intRow, 9).Value)
        strDC1 = Trim(objExcel.Cells(intRow, 10).Value)
        strDC2 = Trim(objExcel.Cells(intRow, 11).Value)
        strDescription = Trim(objExcel.Cells(intRow, 12).Value)
    
'Getting info for creating Email account
     strmsExchHomeServerName = objExcel.Cells(intRow, 13).Value
     strmail = Trim(objExcel.Cells(intRow, 14).Value)
   
     strmailnickname = Trim(objExcel.Cells(intRow, 15).Value)
     strmDBUseDefaults=Trim(objExcel.Cells(intRow, 16).Value)
     strhomeMDB = objExcel.Cells(intRow, 17).Value
     'strproxyAddresses = objExcel.Cells(intRow, 18).Value

Set objContainer = GetObject("LDAP://" & strOU & _
objRootLDAP.Get("defaultNamingContext"))
'Calling Sub routine to read information and create mailbox

Call GetInfo()
call CreateMailBox()
'Clean up variable to avoid it reput container
Set objContainer = Nothing
intRow = intRow + 1
Loop

' Build the actual User from data in strSheet by using a Sub Function

Sub GetInfo()
  Set objUser = objContainer.Create("User", "cn=" & strCN)
        objUser.sAMAccountName = strSam
        objUser.givenName = strFirst
        objUser.sn = strLast
        objUser.userPrincipalName = strPrincipalName
        objUser.DisplayName = strDisplayName
        objUser.Description = strDescription
        objUser.SetInfo

      

' Separate section to enable account with its password
     objUser.SetPassword strPWD
     objUser.Put"userAccountControl", 512       
     'objUser.pwdLastSet = 0
     objUser.SetInfo
    
WScript.Echo(" User Account "& strSam & " has been created")

End Sub

'Sub function to create Mailbox
Sub CreateMailBox()

Set objMailbox = objUser
objMailbox.homeMDB = strhomeMDB
objMailbox.CreateMailbox strhomeMDB
objMailbox.msExchHomeServerName = strmsExchHomeServerName
objMailbox.mail = strmail
objMailbox.mailnickname = strmailnickname
objUser.SetInfo
End Sub

objExcel.Quit

WScript.Quit


_____________________________

chris
 
 
Post #: 1
 
 RE: adding user to groups - 4/2/2008 12:17:56 PM   
  dm_4ever


Posts: 2641
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Have you taken a look at the script on MS site?

http://www.microsoft.com/technet/scriptcenter/scripts/ad/groups/adgpvb03.mspx

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to boston18)
 
 
Post #: 2
 
 RE: adding user to groups - 4/3/2008 12:44:39 AM   
  boston18

 

Posts: 2
Score: 0
Joined: 4/2/2008
Status: offline
Hi DM,

Thanks For checking out my post. I did read that prior to posting. I was wondering if that was the best way to do it. Since I am very new to scripting I was also a little confused on that as it looked like the values were hard coded and since the script is creating users from a spreadsheet it would be a different user every time and I was a little confused on how to modify it for that situation. thank you for your time in reviewing my pst.

_____________________________

chris

(in reply to dm_4ever)
 
 
Post #: 3
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> adding user to groups Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts