Page 1 of 1 1
Topic Options
#136195 - 2005-03-23 11:24 AM Add Domain group to local groups...
Duncman Offline
Fresh Scripter

Registered: 2005-03-10
Posts: 5
Loc: England, UK
Hi,

I've searched the board and can find lots of adding users to groups, but not groups to groups...

I have some script to view the local users on a network pc, then I can select a domain user and add them in as a local admin. This works fine. However as soon as I add domain groups as well as users to the listview and then select an object to add to the local machine, the scripts bombs out. Here is the script to populate the list

Code:
$domain=@ldomain
$GroupObj=GetObject("WinNT://"+ @ldomain + "/Domain Users")
$domaingroups=GetObject("WinNT://"+@ldomain)
$LocalAdminTabPage.Textbox1.Text=@CRLF+"Retrieving Domain User & Group List from Active Directory"
For each $UserObj in $GroupObj.Members
$Userlist.Items.Add($UserObj.Name)
$Userlist.Sorted="True"
NEXT
For each $Group in $domaingroups
$Userlist.Items.Add($Group.Name)
NEXT



and here is the adding bit :

Code:
Function AddUser()

$usertoadd=$UserList.FocusedItem.SubItems(0).Text
$group.Add("WinNT://"+ @ldomain + "/" + $usertoadd)
If @Error
Messagebox("Could not add user to Local Admins","Error",16)
ELSE
$confirm=Messagebox($usertoadd+" added to local admins on "+$target+". Add another?","Account Added",4)
ENDIF
IF $Confirm<>6
Cancel()
CheckAdminButton_Click()
ELSE
CheckAdminButton_Click()
ENDIF
EndFunction



($group is defined further up in the script as getobject("WinNT://"+$target+"/Administrators"))

Basically, if the domain groups are not included in the list view, the script works, when they are the adding function bombs.

Any help gratefully received!

Thanks.

Top
#136196 - 2005-03-23 11:31 AM Re: Add Domain group to local groups...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
you say bombs.
I ask what that means.

you have error checking there and I quess it at least fails on:
$group.Add("WinNT://"+ @ldomain + "/" + $usertoadd)

so, what does mean bombing?
_________________________
!

download KiXnet

Top
#136197 - 2005-03-23 11:37 AM Re: Add Domain group to local groups...
Duncman Offline
Fresh Scripter

Registered: 2005-03-10
Posts: 5
Loc: England, UK
Sorry, bombing means it crashes. It just beeps at me and stops.

The command you mention ($group.Add("WinNT://"+ @ldomain + "/" + $usertoadd)) works fine if the selection list contains users only.

Top
#136198 - 2005-03-23 11:40 AM Re: Add Domain group to local groups...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
k, so I thought it would mean that but your script is full of error checking...
add some, what is crucial is to know where does it crash and what are the causes.
what-goes-in-what-comes-out of the crash is must.

thanks.
_________________________
!

download KiXnet

Top
#136199 - 2005-03-23 05:41 PM Re: Add Domain group to local groups...
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
how about this udf GroupAdd()

example...
Code:

$target = @DOMAIN + '/' + @WKSTA
$ = groupadd($target,'administrators',@DOMAIN + '\Domain Users')


Top
#136200 - 2005-03-29 04:36 PM Re: Add Domain group to local groups...
Anonymous
Unregistered


Yeah, that does the job but I still can't have it add when I select a group from a list, but this is a workable solution.

Thanks.

Top
#136201 - 2005-03-29 08:00 PM Re: Add Domain group to local groups...
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Quote:

I still can't have it add when I select a group from a list




What do you mean by that exactly?

Here is another example, not in a UDF (Function) format, but should give you a little more of an idea of how it works. But I assume that Bryce's UDF does work too, but maybe we need to see how you're calling it and using it.

Can you post your code here so we can see how you're using it?

Code:
Dim $Computer,$AccountToAdd,$GroupToAdd,$GroupToAddTo,$Domain,$Group,$User
$Computer = 'workstation15'
$AccountToAdd = 'FMLAST'
$GroupToAdd = '$MyCorp-Admins'
$GroupToAddTo = 'Administrators'
$Domain = 'MyCorp'
 
; Modify the $GroupToAdd or $AccountToAdd "groups need ,group, accounts need ,account"
$Group = GetObject('WinNT://' + $Computer + '/' + $GroupToAddTo + ',group')
$User = GetObject('WinNT://' + $Domain + '/' + $GroupToAdd + ',group')
; $User = GetObject('WinNT://' + $Domain + '/' + $AccountToAdd + ',user')
$Group.Add($User.ADsPath)
fnCOMErr(@ERROR)
? 'Return value: ' +@ERROR +' '+@SERROR
 
Function fnCOMErr($lErr)
If $lErr<0 $lErr=VAL("&"+Right(DecToHex($lErr),4)) EndIf
Exit $lErr
Endfunction


Top
#136202 - 2005-03-30 01:03 PM Re: Add Domain group to local groups...
Anonymous
Unregistered


Sorry, I'm got my forums a bit muddled here. The list bit comes from KixForms.
I have a list of users, use the FocusItems.Subitems.Text handle so as I can pick a user and click add. Which works, but as soon as I select a group and click add the script crashes.

But the solution above is fine for me. Thanks muchly!

Top
#136203 - 2005-03-30 01:04 PM Re: Add Domain group to local groups...
Duncman Offline
Fresh Scripter

Registered: 2005-03-10
Posts: 5
Loc: England, UK
...and sorry, I forgot to login
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 259 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.059 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org