Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add users from A.D. to a local group via excel sheet 1

Status
Not open for further replies.

arilvade

IS-IT--Management
Mar 17, 2005
32
US
This code works fine without the excel fuction.

How can I get a list of users via excel and add to
a local group?


strComputer = "computernamehere"
Set objGroup = GetObject("WinNT://" & strComputer & "/users")
Set objUser = GetObject("WinNT://domain/username")
objGroup.Add(objUser.ADsPath)
 
Why don't you post what you have tried...including the excel parts?

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open _
("C:\Scripts\New_users.xls")
intRow = 2
Do Until objExcel.Cells(intRow,1).Value = ""
strComputer = "dellcat01"
Set objGroup = GetObject("WinNT://" & strComputer & "/users")

Set objUser = GetObject("WinNT://psbos & objworkbook")
'the problem is here; how do I grab
'user from A.D. with a list via excel?


objGroup.Add(objUser.ADsPath)
intRow = intRow + 1
Loop
objExcel.Quit

 
Maybe something like this...considering your usernames are in the form of domainname\username

Code:
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open _
    ("C:\Scripts\New_users.xls")
intRow = 2
Do Until objExcel.Cells(intRow,1).Value = ""
	strComputer = "dellcat01"
	Set objGroup = GetObject("WinNT://" & strComputer & "/users")
	Set objUser = GetObject("WinNT://" & objExcel.Cells(intRow, 1).Value)	                     
	objGroup.Add(objUser.ADsPath)
	
	intRow = intRow + 1
Loop
objExcel.Quit

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top