Check my script

G

Guest

Hi,
Moving forward with AD I am learning that I require the WMI skill to take
full advantage of GPO's.
I would like my script to Add a specified group to the pc's Local Admin
account.
My script won't run and has no form on debugging.
I modified the script to suite my requirements.
Pls can someone check it out and provide some input
Thanx in advance ,
Julian
'Beginning Of the Script

On Error Resume Next

'get main objects/variables
Set ws = WScript.CreateObject ( "WScript.Shell" )
compname = ws.ExpandEnvironmentStrings ( "%COMPUTERNAME%" )
Set adGrp = GetObject ( "WinNT://" & compname & "/Administrators,group" )

'add domain groups to local admin group
adGrp.Add ( "WinNT://coronation/Desktop Admins,group" )

'End of the Script
 
T

Torgeir Bakken \(MVP\)

Julian said:
Hi,
Moving forward with AD I am learning that I require the WMI skill to take
full advantage of GPO's.
I would like my script to Add a specified group to the pc's Local Admin
account.
My script won't run and has no form on debugging.
I modified the script to suite my requirements.
Pls can someone check it out and provide some input
Thanx in advance ,
Julian
'Beginning Of the Script

On Error Resume Next

'get main objects/variables
Set ws = WScript.CreateObject ( "WScript.Shell" )
compname = ws.ExpandEnvironmentStrings ( "%COMPUTERNAME%" )
Set adGrp = GetObject ( "WinNT://" & compname & "/Administrators,group" )

'add domain groups to local admin group
adGrp.Add ( "WinNT://coronation/Desktop Admins,group" )
Hi

Note that your script is not using WMI, it is using ADSI, and that
would be better handled in microsoft.public.windows.server.scripting
or microsoft.public.adsi.general.

Anyway, try this:


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

sDomainGroup = "Desktop Admins"

sNetBIOSDomain = oWshNet.UserDomain

sComputer = oWshNet.ComputerName

Set oLocalGroup = GetObject("WinNT://" & sComputer & "/Administrators,group")

Set oDomainGroup = GetObject("WinNT://" & sNetBIOSDomain & "/" _
& sDomainGroup & ",group")

' suppress errors in case group is already a member
On Error Resume Next
oLocalGroup.Add(oDomainGroup.ADsPath)
On Error Goto 0
'--------------------8<----------------------

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

Someone

Julian,
just a couple of minor words to add WRT debugging your script and
running it -
a) you should be able to run your script in the debugger if you run your
script with the wscript command line switch
-- look at your WSH docs.. if you don't have these, download them ..
likewise for the debugger (download if you don't have one). Both downloads
are available free from MS. 0
b) if your script wouldn't run - it would be nice to know the error message
when posting - granted the error is likely something to the effect of
....can't create object... but knowing what is going wrong would help those
considering helping you.
Good luck with your script.

X
 
S

Someone

.... of course commenting out the 'on error' statement would be needed to
first find out what the errors were!!! Oversight on first pass- sorry .

X
 
G

Guest

Hi Torgeir,
I'm getting an error on line:12 Character:1
line 12 = oLocalGroup.Add(oDomainGroup.ADsPath) = Chinese to me!
Thanx,
Julian
 
T

Torgeir Bakken \(MVP\)

Julian said:
Hi Torgeir,
I'm getting an error on line:12 Character:1
line 12 = oLocalGroup.Add(oDomainGroup.ADsPath) = Chinese to me!
Hi

Could you post the exact error message and the exact script you
are using?
 
G

Guest

Yes,
I'm using the script you supplied.
'--------------------8<----------------------
Set oWshNet = CreateObject("WScript.Network")

sDomainGroup = "Desktop Admins"

sNetBIOSDomain = oWshNet.UserDomain

sComputer = oWshNet.ComputerName

Set oLocalGroup = GetObject("WinNT://" & sComputer & "/Administrators,group")

Set oDomainGroup = GetObject("WinNT://" & sNetBIOSDomain & "/" _
& sDomainGroup & ",group")

' suppress errors in case group is already a member
On Error Resume Next
oLocalGroup.Add(oDomainGroup.ADsPath)
On Error Goto 0
'--------------------8<----------------------

The error is:
Line:12
Character:1
Error: 0x80005000
code: 0x80005000
source:null

Thanx,
Julian
 
T

Torgeir Bakken \(MVP\)

Julian said:
Yes,
I'm using the script you supplied.
'--------------------8<----------------------
Set oWshNet = CreateObject("WScript.Network")

sDomainGroup = "Desktop Admins"

sNetBIOSDomain = oWshNet.UserDomain

sComputer = oWshNet.ComputerName

Set oLocalGroup = GetObject("WinNT://" & sComputer & "/Administrators,group")

Set oDomainGroup = GetObject("WinNT://" & sNetBIOSDomain & "/" _
& sDomainGroup & ",group")

' suppress errors in case group is already a member
On Error Resume Next
oLocalGroup.Add(oDomainGroup.ADsPath)
On Error Goto 0
'--------------------8<----------------------

The error is:
Line:12
Character:1
Error: 0x80005000
Hi

Error hex 0x80005000 / decimal -2147463168 is:

E_ADS_BAD_PATHNAME
An invalid directory pathname was passed

so that means that the script is not able to connect to the group.

If you after the line
sNetBIOSDomain = oWshNet.UserDomain
add the line
MsgBox sNetBIOSDomain
does it display the domain name the group is in?

If you from the Administrators group temporary remove the
"<domain>\Domain Admins" group and change the sDomainGroup variable
in the script to contain

sDomainGroup = "Domain Admins"

and then run the script, is then "Domain Admins" added back, or do you
get an error for that one also?
 
G

Guest

Hi Torgeir,
I got it to work!Yay.
I tried to get clever and changed
sNetBIOSDomain = "domain"

This did not work, so I change the domian group to one word and this got it
working.
Dunno why but it prefered the one word group name ?!
Thanx for all,
Julian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top