Adding multiple users or groups to local groups 
Author Message
 Adding multiple users or groups to local groups

Hello all,

I wrote this script to add a user or group to a local workstation group, but
I'm trying to figure out how to add multiple users/groups to a local
workstation group.
i.e. I need to add 2 or more global domain groups into the local admin and 2
or more into the local power users group.

I'm still kinda new at VBScripting so if my script looks like a dogs
breakfeast please forgive me.

Anyway, anyone have a suggestion on how to approach this or even some tips
to tweak this script for better error handling, logging, or runtime output
to let the user running the script know whats happening?

TIA

Ford...

Script below.......................

'FILE: addto_local_group.vbs
'AUTH: Ford Prefect
'DATE: Sept 20/02
'DESC: Adds users or groups from a domain to a workstation's local groups

Option Explicit
On Error Resume Next
Dim sDomain, sUser, oUser, oGroup, sGroup
Dim sComputerName, oWshNet

'Set the name of your Domain here
'This is the domain where your users or groups are located in
sDomain = "MyDomain"
'Set the name of the user or group you want to add to the local group
sUser = "Domain Users"
Set oUser = GetObject("WinNT://" & sDomain & "/" & sUser)
If err.number <> 0 Then
  Wscript.Echo("An error has occured." & Err.Number)
  WScript.Quit
End If

'This grabs the computer name from the workstation
'you are running the script on
Set oWshNet = CreateObject("Wscript.Network")
sComputerName = oWshNet.ComputerName
If err.number <> 0 Then
  Wscript.Echo("An error has occured." & Err.Number)
  WScript.Quit
End If

'Set the name of the local group you want to add to here
sGroup = "Power Users"
Set oGroup = GetObject("WinNT://" & sComputerName & "/" & sGroup)
If err.number <> 0 Then
  Wscript.Echo("An error has occured." & Err.Number)
  WScript.Quit
End If

'This adds the user or group to the local group specified
oGroup.add(oUser.ADsPath)

'Clean up objects
Set oGroup = nothing
Set oWshNet = nothing
Set oUser = nothing

Wscript.Quit



Wed, 09 Mar 2005 21:17:44 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Add Domain Users Group to Powe Users Group in Script

2. help Adding a Domain group to a Local Group

3. VB script: adding AD group to local administrators group

4. Add domain group to local group

5. Adding domain groups to gthe local administrator group

6. Adding a Domain Global group to a machine local group in Windows 2000

7. Adding a domain group to local administrators group

8. Add Global group to Local Group

9. How do I add a domain global-groups in a member-server local group

10. Add and remove AD user to and from local group

11. add user to local win2k administrator group

12. Add user to local W2kAS admin group?

 

 
Powered by phpBB® Forum Software