?
Solved

Have a file with Machine name and Ntlogin. Need to add the users in the local Administrator group of the machine.

Posted on 2008-10-23
61
Medium Priority
?
243 Views
Last Modified: 2012-06-27
Hi,

Have a file with Machine name and Ntlogin. Need to add the users in the local Administrator group of the machine.
For each machine with the user next to him.

File as this

Machine name,Username/NT Login

Is there a way to run a script and get this done remotely.

Regards
Sharath
0
Comment
Question by:bsharath
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 37
  • 24
61 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 22793081
This should do it...
SourceFile = "C:\SourceFile.txt"
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
 
arrData = Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)
 
For each item in arrData
  arrValue = Split(item,",")
  PC=arrValue(0)
  User=arrValue(1)
  AddUserToAdmin (User, PC)
Next
 
wscript.quit
 
Sub AddUserToAdmin (strUser, strPC)
  Dim objUser : Set objUser = GetObject("WinNT://" & strPC & "/" strUser)
  Dim objAdmin : Set objAdmin = GetObject("WinNT://" & strPC & "/Administrators")
  objAdmin.Add (objUser.ADsPath)
  Set objAdmin = Nothing
  Set objUser = Nothing
End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 22793113
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      10
Char:      28
Error:      Cannot use parentheses when calling a Sub
Code:      800A0414
Source:       Microsoft VBScript compilation error

---------------------------
OK  
---------------------------
0
 
LVL 11

Author Comment

by:bsharath
ID: 22793114
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      10
Char:      28
Error:      Cannot use parentheses when calling a Sub
Code:      800A0414
Source:       Microsoft VBScript compilation error

---------------------------
OK  
---------------------------
0
Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

 
LVL 67

Expert Comment

by:sirbounty
ID: 22793126
Change line 10 from this:
  AddUserToAdmin (User, PC)
to this:
  AddUserToAdmin User, PC
0
 
LVL 11

Author Comment

by:bsharath
ID: 22793140
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      16
Char:      66
Error:      Expected ')'
Code:      800A03EE
Source:       Microsoft VBScript compilation error

---------------------------
OK  
---------------------------
0
 
LVL 11

Author Comment

by:bsharath
ID: 22793141
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      16
Char:      66
Error:      Expected ')'
Code:      800A03EE
Source:       Microsoft VBScript compilation error

---------------------------
OK  
---------------------------
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22793180
What does the message reveal in this version?
SourceFile = "C:\SourceFile.txt"
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
 
arrData = Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)
 
For each item in arrData
  arrValue = Split(item,",")
  PC=Trim(arrValue(0))
  User=Trim(arrValue(1))
  AddUserToAdmin User, PC
Next
 
wscript.quit
 
Sub AddUserToAdmin (strUser, strPC)
  wscript.echo "Adding " & strUser & " to Administrators group on " & strPC
  Dim objUser : Set objUser = GetObject("WinNT://" & strPC & "/" strUser)
  Dim objAdmin : Set objAdmin = GetObject("WinNT://" & strPC & "/Administrators")
  objAdmin.Add (objUser.ADsPath)
  Set objAdmin = Nothing
  Set objUser = Nothing
End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 22793201
I getb this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      17
Char:      66
Error:      Expected ')'
Code:      800A03EE
Source:       Microsoft VBScript compilation error

---------------------------
OK  
---------------------------
0
 
LVL 11

Author Comment

by:bsharath
ID: 22793202
I getb this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      17
Char:      66
Error:      Expected ')'
Code:      800A03EE
Source:       Microsoft VBScript compilation error

---------------------------
OK  
---------------------------
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22793239
Odd...not sure what ')' it's expecting.
If this version doesn't work - comment out that line (should be line 18 now...starts with Dim objUser...by placing a ' at the start of it)
SourceFile = "C:\SourceFile.txt"
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
 
arrData = Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)
 
For each item in arrData
  arrValue = Split(item,",")
  PC=Trim(arrValue(0))
  User=Trim(arrValue(1))
  AddUserToAdmin User, PC
Next
 
wscript.quit
 
Sub AddUserToAdmin (strUser, strPC)
  wscript.echo "Adding " & strUser & " to Administrators group on " & strPC
  UserPath=strPC & "/" & strUser
  Dim objUser : Set objUser = GetObject("WinNT://" & UserPath)
  Dim objAdmin : Set objAdmin = GetObject("WinNT://" & strPC & "/Administrators")
  objAdmin.Add (objUser.ADsPath)
  Set objAdmin = Nothing
  Set objUser = Nothing
End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 22793269
Now i get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      9
Char:      3
Error:      Subscript out of range: '[number: 1]'
Code:      800A0009
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22793283
Looks to be the input file...
Presumably it's laid out like
ComputerName,UserName
correct?
0
 
LVL 11

Author Comment

by:bsharath
ID: 22793325
Sorry have a ; instead of a ,

Now i get this

---------------------------
Windows Script Host
---------------------------
Adding Echj to Administrators group on Dev-mrd01
---------------------------
OK  
---------------------------


Then this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      18
Char:      17
Error:      The group name could not be found.
Code:      800708AC
Source:       (null)

---------------------------
OK  
---------------------------

0
 
LVL 11

Author Comment

by:bsharath
ID: 22793326
Sorry have a ; instead of a ,

Now i get this

---------------------------
Windows Script Host
---------------------------
Adding Echj to Administrators group on Dev-mrd01
---------------------------
OK  
---------------------------


Then this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      18
Char:      17
Error:      The group name could not be found.
Code:      800708AC
Source:       (null)

---------------------------
OK  
---------------------------

0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22793349
I think the user/pc are off...I was using user,pc - but it looks like you said it was pc,user?Sorry - it's late here...if this still fails to work, check that the Administrators group exists as that name on the target device.
SourceFile = "C:\SourceFile.txt"
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
 
arrData = Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)
 
For each item in arrData
  arrValue = Split(item,",")
  PC=Trim(arrValue(0))
  User=Trim(arrValue(1))
  AddUserToAdmin PC, User
Next
 
wscript.quit
 
Sub AddUserToAdmin (strPC, strUser)
  UserPath=strPC & "/" & strUser
  Dim objUser : Set objUser = GetObject("WinNT://" & UserPath)
  Dim objAdmin : Set objAdmin = GetObject("WinNT://" & strPC & "/Administrators")
  objAdmin.Add (objUser.ADsPath)
  Set objAdmin = Nothing
  Set objUser = Nothing
End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 22793361
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      17
Char:      17
Error:      Unspecified error
Code:      80004005
Source:       (null)

---------------------------
OK  
---------------------------

Should i use it as
USer,pC?
0
 
LVL 11

Author Comment

by:bsharath
ID: 22793363
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      17
Char:      17
Error:      Unspecified error
Code:      80004005
Source:       (null)

---------------------------
OK  
---------------------------

Should i use it as
USer,pC?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22793373
No I corrected it in the code - should be
pc,user

To reduce the space, I'll just update the subroutine...try replacing the entire sub at the bottom with this one:
It should pop up a box that says

Dev-mrd01/Echj

Does that user already exist on the target machine?  Or are you trying to add a domain user?



Sub AddUserToAdmin (strPC, strUser)
  UserPath=strPC & "/" & strUser
msgbox UserPath
  Dim objUser : Set objUser = GetObject("WinNT://" & UserPath)
  Dim objAdmin : Set objAdmin = GetObject("WinNT://" & strPC & "/Administrators")
  objAdmin.Add (objUser.ADsPath)
  Set objAdmin = Nothing
  Set objUser = Nothing
End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 22793382
I get this

---------------------------

---------------------------
Echj/Dev-mrd01
---------------------------
OK  
---------------------------

But get this later

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      18
Char:      17
Error:      Unspecified error
Code:      80004005
Source:       (null)

---------------------------
OK  
---------------------------
0
 
LVL 11

Author Comment

by:bsharath
ID: 22793383
I get this

---------------------------

---------------------------
Echj/Dev-mrd01
---------------------------
OK  
---------------------------

But get this later

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      18
Char:      17
Error:      Unspecified error
Code:      80004005
Source:       (null)

---------------------------
OK  
---------------------------
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22793398
Hmm..something wrong with the add routine...another test:

Sub AddUserToAdmin (strPC, strUser)
  UserPath=strPC & "/" & strUser
  Dim objUser : Set objUser = GetObject("WinNT://" & UserPath)
msgbox objUser.Name & vbNewLine & objUser.ADsPath
  Dim objAdmin : Set objAdmin = GetObject("WinNT://" & strPC & "/Administrators")
msgbox objAdmin.Name
  objAdmin.Add (objUser.ADsPath)
  Set objAdmin = Nothing
  Set objUser = Nothing
End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 22793416
I get this
---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      17
Char:      17
Error:      Unspecified error
Code:      80004005
Source:       (null)

---------------------------
OK  
---------------------------
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22793421
no popups at all?
Does this user account already exist on the target device?
0
 
LVL 11

Author Comment

by:bsharath
ID: 22793430
No popup's just the error.
No the user is not a member of Administrators group...
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22793436
Right, but the user you're trying to add...is that user already defined on the target PC, or is this supposed to be a domain account?
0
 
LVL 11

Author Comment

by:bsharath
ID: 22793450
The user i am trying to add is a Domain Account. I have running from an account with Domain Admin permissions on to a Remote machine name in the file with the Domain User name.

0
 
LVL 11

Author Comment

by:bsharath
ID: 22793451
The user i am trying to add is a Domain Account. I have running from an account with Domain Admin permissions on to a Remote machine name in the file with the Domain User name.

0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22793478
That changes things...we're using the WinNT provider to do this, so we either have to switch to LDAP, or you might be able to get by with this change:

Note the change to the objUser path - you'll need to enter your actual domain name there...
Sub AddUserToAdmin (strPC, strUser)
  Dim objUser : Set objUser = GetObject("WinNT://YourDomain/" & strUser)
  Dim objAdmin : Set objAdmin = GetObject("WinNT://" & strPC & "/Administrators")
  objAdmin.Add (objUser.ADsPath)
  Set objAdmin = Nothing
  Set objUser = Nothing
End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 22793501
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      17
Char:      18
Error:      The network path was not found.
Code:      80070035
Source:       (null)

---------------------------
OK  
---------------------------
 
I have the txt file as

Machine name,Username/NT Login
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22793508
What do you mean by Username/NT Login
Can you post a line or two from your file?
What's your domain name?
0
 
LVL 11

Author Comment

by:bsharath
ID: 22793515
Domain Name " Development"

I Have this in the file
Dev-mrd01,SharathK
Inside,Sharathk
Dev-mrd01,Echj
0
 
LVL 11

Author Comment

by:bsharath
ID: 22793517
Domain Name " Development"

I Have this in the file
Dev-mrd01,SharathK
Inside,Sharathk
Dev-mrd01,Echj
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22793526
Full script...let me know...
SourceFile = "C:\SourceFile.txt"
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
 
arrData = Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)
 
For each item in arrData
  arrValue = Split(item,",")
  PC=Trim(arrValue(0))
  User=Trim(arrValue(1))
  AddUserToAdmin User, PC
Next
 
wscript.quit
 
Sub AddUserToAdmin (strPC, strUser)
  Dim objUser : Set objUser = GetObject("WinNT://Development/" & strUser)
  Dim objAdmin : Set objAdmin = GetObject("WinNT://" & strPC & "/Administrators")
  objAdmin.Add (objUser.ADsPath)
  Set objAdmin = Nothing
  Set objUser = Nothing
End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 22793543
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      17
Char:      18
Error:      The network path was not found.
Code:      80070035
Source:       (null)

---------------------------
OK  
---------------------------

I have 5 machine names with users and all machines and NTlogins are live...
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22793554
So, you can successfully ping Dev-mrd01?
0
 
LVL 11

Author Comment

by:bsharath
ID: 22793558
Yes i can
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22793596
Odd - try moving another line up top in your file, just for testing.  And you do have access to these PCs as an Admin, correct?

Other than that, try this version...doubt it'll yield much different though.
SourceFile = "C:\SourceFile.txt"
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
 
arrData = Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)
 
For each item in arrData
  arrValue = Split(item,",")
  PC=Trim(arrValue(0))
  User=Trim(arrValue(1))
  AddUserToAdmin User, PC
Next
 
wscript.quit
 
Sub AddUserToAdmin (strPC, strUser)
  Dim objUser : Set objUser = GetObject("WinNT://Development/" & strUser)
  Dim objPC : Set objPC = GetObject("WinNT://" & strPC)
  Dim objAdmin : Set objAdmin = GetObject(objPC.ADsPath & "/Administrators")  
 
  objAdmin.Add (objUser.ADsPath)
  Set objAdmin = Nothing
  Set objPC = Nothing
  Set objUser = Nothing
End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 22793669
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      18
Char:      18
Error:      The network path was not found.
Code:      80070035
Source:       (null)

---------------------------
OK  
---------------------------
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22794438
That looks like it's having trouble finding the group Administrators...the line before seems to have gotten to the PC okay.
Can you verify the Admin group name is Administrators and exists on that device?
0
 
LVL 11

Author Comment

by:bsharath
ID: 22794555
Yes The group name is Administrators and it exists...
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22797200
Tested this further on a couple of my work computers with no problem.

Line 17 appears to be working, so the computer is being discovered.  Perhaps the adspath is incorrect?

Change these lines - I dropped a new line in between them:


  Dim objPC : Set objPC = GetObject("WinNT://" & strPC)
Msgbox objPC.AdsPath & "/Administrators"
  Dim objAdmin : Set objAdmin = GetObject(objPC.ADsPath & "/Administrators")

I'd like to know what pop up message you get.
0
 
LVL 11

Author Comment

by:bsharath
ID: 22797268
First got this
---------------------------

---------------------------
WinNT://Echj/Administrators
---------------------------
OK  
---------------------------

Then this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      19
Char:      18
Error:      The network path was not found.
Code:      80070035
Source:       (null)

---------------------------
OK  
---------------------------
0
 
LVL 11

Author Comment

by:bsharath
ID: 22797269
First got this
---------------------------

---------------------------
WinNT://Echj/Administrators
---------------------------
OK  
---------------------------

Then this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      19
Char:      18
Error:      The network path was not found.
Code:      80070035
Source:       (null)

---------------------------
OK  
---------------------------
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22813730
I've been unable to reproduce this - it works on my network with 5 different devices.
Can you try reordering your input list and see if it's just a problem with that one device?
0
 
LVL 11

Author Comment

by:bsharath
ID: 22819908
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      19
Char:      18
Error:      The network path was not found.
Code:      80070035
Source:       (null)

---------------------------
OK  
---------------------------


Full code as in snippet

The txt file is as

Machinename,Username
SourceFile = "C:\SourceFile.txt"
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
 
arrData = Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)
 
For each item in arrData
  arrValue = Split(item,",")
  PC=Trim(arrValue(0))
  User=Trim(arrValue(1))
  AddUserToAdmin User, PC
Next
 
wscript.quit
 
Sub AddUserToAdmin (strPC, strUser)
  Dim objUser : Set objUser = GetObject("WinNT://Development/" & strUser)
  Dim objPC : Set objPC = GetObject("WinNT://" & strPC)
Msgbox objPC.AdsPath & "/Administrators"
  Dim objAdmin : Set objAdmin = GetObject(objPC.ADsPath & "/Administrators")  
 
  objAdmin.Add (objUser.ADsPath)
  Set objAdmin = Nothing
  Set objPC = Nothing
  Set objUser = Nothing
End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 22819909
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      19
Char:      18
Error:      The network path was not found.
Code:      80070035
Source:       (null)

---------------------------
OK  
---------------------------


Full code as in snippet

The txt file is as

Machinename,Username
SourceFile = "C:\SourceFile.txt"
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
 
arrData = Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)
 
For each item in arrData
  arrValue = Split(item,",")
  PC=Trim(arrValue(0))
  User=Trim(arrValue(1))
  AddUserToAdmin User, PC
Next
 
wscript.quit
 
Sub AddUserToAdmin (strPC, strUser)
  Dim objUser : Set objUser = GetObject("WinNT://Development/" & strUser)
  Dim objPC : Set objPC = GetObject("WinNT://" & strPC)
Msgbox objPC.AdsPath & "/Administrators"
  Dim objAdmin : Set objAdmin = GetObject(objPC.ADsPath & "/Administrators")  
 
  objAdmin.Add (objUser.ADsPath)
  Set objAdmin = Nothing
  Set objPC = Nothing
  Set objUser = Nothing
End Sub

Open in new window

0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22821377
Sorry Sharath, please try this one...
SourceFile = "C:\SourceFile.txt"
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
 
arrData = Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)
 
For each item in arrData
  arrValue = Split(item,",")
  PC=Trim(arrValue(0))
  User=Trim(arrValue(1))
  AddUserToAdmin PC, User
Next
 
wscript.quit
 
Sub AddUserToAdmin (strPC, strUser)
  On Error Resume Next
  Dim objUser : Set objUser = GetObject("WinNT://Development/" & strUser)
  Dim objPC : Set objPC = GetObject("WinNT://" & strPC)
  Dim objAdmin : Set objAdmin = GetObject(objPC.ADsPath & "/Administrators")  
 
  objAdmin.Add (objUser.ADsPath)
  If Err.Number <> 0 Then
    wscript.echo "An error has occured:" & vbNewLine & Err.Description
  End If
  Set objAdmin = Nothing
  Set objPC = Nothing
  Set objUser = Nothing
End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 22848095
Sorry for the delay...
I get this...

a box
An error has occured then this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      8
Char:      3
Error:      Subscript out of range: '[number: 0]'
Code:      800A0009
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------
0
 
LVL 11

Author Comment

by:bsharath
ID: 22848096
Sorry for the delay...
I get this...

a box
An error has occured then this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add Users to Groups in Machines.vbs
Line:      8
Char:      3
Error:      Subscript out of range: '[number: 0]'
Code:      800A0009
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22849160
Apology unnecessary.
That would indicate that there is no PC in the first field...this should test for empty lines:
SourceFile = "C:\SourceFile.txt"
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
 
arrData = Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)
 
For each item in arrData
  If item <> "" Then
    arrValue = Split(item,",")
    PC=Trim(arrValue(0))
    User=Trim(arrValue(1))
    AddUserToAdmin PC, User
  End If
Next
 
wscript.quit
 
Sub AddUserToAdmin (strPC, strUser)
  On Error Resume Next
  Dim objUser : Set objUser = GetObject("WinNT://Development/" & strUser)
  Dim objPC : Set objPC = GetObject("WinNT://" & strPC)
  Dim objAdmin : Set objAdmin = GetObject(objPC.ADsPath & "/Administrators")  
 
  objAdmin.Add (objUser.ADsPath)
  If Err.Number <> 0 Then
    wscript.echo "An error has occured:" & vbNewLine & Err.Description
  End If
  Set objAdmin = Nothing
  Set objPC = Nothing
  Set objUser = Nothing
End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 22849216
I just get this

---------------------------
Windows Script Host
---------------------------
An error has occured:


---------------------------
OK  
---------------------------
0
 
LVL 11

Author Comment

by:bsharath
ID: 22849217
I just get this

---------------------------
Windows Script Host
---------------------------
An error has occured:


---------------------------
OK  
---------------------------
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22849416
If you click OK, do any of them get added?  That's a bypassable error...
0
 
LVL 11

Author Comment

by:bsharath
ID: 22849504
You are right now it add's the use but get that error....

Can i get a done button or a success/failure results file.
0
 
LVL 11

Author Comment

by:bsharath
ID: 22849505
You are right now it add's the use but get that error....

Can i get a done button or a success/failure results file.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22849542
Run the script with

cscript "C:\Add Users to Groups in Machines.vbs"
SourceFile = "C:\SourceFile.txt"
OutputFile = "C:\AdminAddResults.txt"
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objLog : Set objLog = objFSO.CreateTextFile(OutputFile)
 
arrData = Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)
 
For each item in arrData
  If item <> "" Then
    arrValue = Split(item,",")
    PC=Trim(arrValue(0))
    User=Trim(arrValue(1))
    objLog.WriteLine "Attempting to add " & User & " to Admin group on " & PC
    AddUserToAdmin PC, User
  End If
Next
 
objLog.Close
wscript.quit
 
Sub AddUserToAdmin (strPC, strUser)
  On Error Resume Next
  Dim objUser : Set objUser = GetObject("WinNT://Development/" & strUser)
  Dim objPC : Set objPC = GetObject("WinNT://" & strPC)
  Dim objAdmin : Set objAdmin = GetObject(objPC.ADsPath & "/Administrators")  
 
  objAdmin.Add (objUser.ADsPath)
  If Err.Number <> 0 Then
    objLog.WriteLine vbTab "An error has occured:  " & Err.Description
  Else
    objLog.WriteLine vbTab & "...added successfully."
  End If
  Set objAdmin = Nothing
  Set objPC = Nothing
  Set objUser = Nothing
End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 22849576
I get this

C:\>cscript "C:\Add Users to Groups in Machines.vbs"
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\Add Users to Groups in Machines.vbs(29, 28) Microsoft VBScript compilation error: Expected end of statement
0
 
LVL 11

Author Comment

by:bsharath
ID: 22849585
I get this

C:\>cscript "C:\Add Users to Groups in Machines.vbs"
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\Add Users to Groups in Machines.vbs(29, 28) Microsoft VBScript compilation error: Expected end of statement
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 2000 total points
ID: 22849598
Sorry about that...
SourceFile = "C:\SourceFile.txt"
OutputFile = "C:\AdminAddResults.txt"
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objLog : Set objLog = objFSO.CreateTextFile(OutputFile)
 
arrData = Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)
 
For each item in arrData
  If item <> "" Then
    arrValue = Split(item,",")
    PC=Trim(arrValue(0))
    User=Trim(arrValue(1))
    objLog.WriteLine "Attempting to add " & User & " to Admin group on " & PC
    AddUserToAdmin PC, User
  End If
Next
 
objLog.Close
wscript.quit
 
Sub AddUserToAdmin (strPC, strUser)
  On Error Resume Next
  Dim objUser : Set objUser = GetObject("WinNT://Development/" & strUser)
  Dim objPC : Set objPC = GetObject("WinNT://" & strPC)
  Dim objAdmin : Set objAdmin = GetObject(objPC.ADsPath & "/Administrators")  
 
  objAdmin.Add (objUser.ADsPath)
  If Err.Number <> 0 Then
    objLog.WriteLine vbTab & "An error has occured:  " & Err.Description
  Else
    objLog.WriteLine vbTab & "...added successfully."
  End If
  Set objAdmin = Nothing
  Set objPC = Nothing
  Set objUser = Nothing
End Sub

Open in new window

0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22849734
Glad it's working for you - thanx for the grade! :^)
0
 
LVL 11

Author Comment

by:bsharath
ID: 22849754
Thank U very much... Very useful one for me... :-))
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question