Jason

Distinguished
Jul 25, 2003
1,026
0
19,280
Archived from groups: microsoft.public.windowsxp.configuration_manage (More info?)

I am looking to add a domain user to the local admin group
via vb scripting. I have a script to add a local user to
the local group but am uncertain how to modify
appropriately to pull the domain user.

Any help?
 
G

Guest

Guest
Archived from groups: microsoft.public.windowsxp.configuration_manage (More info?)

Jason wrote:

> I am looking to add a domain user to the local admin group
> via vb scripting. I have a script to add a local user to
> the local group but am uncertain how to modify
> appropriately to pull the domain user.
>
> Any help?
Hi


'--------------------8<----------------------

Set oWshNet = CreateObject("WScript.Network")

sUser = "fill in some domain user name here"

sNetBIOSDomain = oWshNet.UserDomain
sComputer = oWshNet.ComputerName

Set oGroup = GetObject("WinNT://" & sComputer & "/Administrators,group")
Set oUser = GetObject("WinNT://" & sNetBIOSDomain & "/" & sUser & ",user")

' suppress errors in case the user is already a member
On Error Resume Next
oGroup.Add(oUser.ADsPath)
On Error Goto 0
'--------------------8<----------------------


If the computers are in another domain than the user you
want to add, you will need to hard code the domain name
the user belongs to in the variable "sNetBIOSDomain".



--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx
 
G

Guest

Guest
Archived from groups: microsoft.public.windowsxp.configuration_manage (More info?)

To take this one step further, the DOMAIN USERS group had
been added to the Local Admin group. How can I, via
vbscript, remove that group from the workstations?

Thanks,
>-----Original Message-----
>Jason wrote:
>
>> I am looking to add a domain user to the local admin
group
>> via vb scripting. I have a script to add a local user
to
>> the local group but am uncertain how to modify
>> appropriately to pull the domain user.
>>
>> Any help?
>Hi
>
>
>'--------------------8<----------------------
>
>Set oWshNet = CreateObject("WScript.Network")
>
>sUser = "fill in some domain user name here"
>
>sNetBIOSDomain = oWshNet.UserDomain
>sComputer = oWshNet.ComputerName
>
>Set oGroup = GetObject("WinNT://" & sComputer
& "/Administrators,group")
>Set oUser = GetObject("WinNT://" & sNetBIOSDomain & "/" &
sUser & ",user")
>
>' suppress errors in case the user is already a member
>On Error Resume Next
>oGroup.Add(oUser.ADsPath)
>On Error Goto 0
>'--------------------8<----------------------
>
>
>If the computers are in another domain than the user you
>want to add, you will need to hard code the domain name
>the user belongs to in the variable "sNetBIOSDomain".
>
>
>
>--
>torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
>Administration scripting examples and an ONLINE version of
>the 1328 page Scripting Guide:
>http://www.microsoft.com/technet/scriptcenter/default.mspx
>.
>
 
G

Guest

Guest
Archived from groups: microsoft.public.windowsxp.configuration_manage (More info?)

anonymous@discussions.microsoft.com wrote:

> To take this one step further, the DOMAIN USERS group had
> been added to the Local Admin group. How can I, via
> vbscript, remove that group from the workstations?
Hi


'--------------------8<----------------------
Set oWshNet = CreateObject("WScript.Network")

' computer name
sNode = oWshNet.ComputerName

' group name to remove user or group from
Set oGroup = GetObject("WinNT://" & sNode & "/Administrators")

' loop through all member of the group
For Each oUser In oGroup.Members

' get the name and make it lowercase
sGroupEntry = LCase(oUser.Name)

If (sGroupEntry = "domain users") Then
' remove entry from group
oGroup.Remove oUser.ADsPath
End if
Next
'--------------------8<----------------------


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx
 

Jason

Distinguished
Jul 25, 2003
1,026
0
19,280
Archived from groups: microsoft.public.windowsxp.configuration_manage (More info?)

Thanks Much.

These scripts really help.
>-----Original Message-----
>anonymous@discussions.microsoft.com wrote:
>
>> To take this one step further, the DOMAIN USERS group
had
>> been added to the Local Admin group. How can I, via
>> vbscript, remove that group from the workstations?
>Hi
>
>
>'--------------------8<----------------------
>Set oWshNet = CreateObject("WScript.Network")
>
>' computer name
>sNode = oWshNet.ComputerName
>
>' group name to remove user or group from
>Set oGroup = GetObject("WinNT://" & sNode
& "/Administrators")
>
>' loop through all member of the group
>For Each oUser In oGroup.Members
>
> ' get the name and make it lowercase
> sGroupEntry = LCase(oUser.Name)
>
> If (sGroupEntry = "domain users") Then
> ' remove entry from group
> oGroup.Remove oUser.ADsPath
> End if
>Next
>'--------------------8<----------------------
>
>
>--
>torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
>Administration scripting examples and an ONLINE version of
>the 1328 page Scripting Guide:
>http://www.microsoft.com/technet/scriptcenter/default.mspx
>.
>
 
G

Guest

Guest
Archived from groups: microsoft.public.windowsxp.configuration_manage (More info?)

You can also do this pretty easily via the "net localgroup" command (though
this isn't really VBScript, you could call it from a vbs):

net localgroup Administrators /add DOMAIN\USERNAME

--
Please reply in newsgroup.

This posting is provided "AS IS" with no warranties, and confers no rights.



"Jason" <jason.brimhall@questar.com> wrote in message
news:015a01c4904e$c8fa1d20$a401280a@phx.gbl...
>I am looking to add a domain user to the local admin group
> via vb scripting. I have a script to add a local user to
> the local group but am uncertain how to modify
> appropriately to pull the domain user.
>
> Any help?
 

TRENDING THREADS