Duncman
(Fresh Scripter)
2005-03-23 11:24 AM
Add Domain group to local groups...

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.


LonkeroAdministrator
(KiX Master Guru)
2005-03-23 11:31 AM
Re: Add Domain group to local groups...

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?


Duncman
(Fresh Scripter)
2005-03-23 11:37 AM
Re: Add Domain group to local groups...

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.


LonkeroAdministrator
(KiX Master Guru)
2005-03-23 11:40 AM
Re: Add Domain group to local groups...

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.


Bryce
(KiX Supporter)
2005-03-23 05:41 PM
Re: Add Domain group to local groups...

how about this udf GroupAdd()

example...
Code:

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



**DONOTDELETE**
(Lurker)
2005-03-29 04:36 PM
Re: Add Domain group to local groups...

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.


NTDOCAdministrator
(KiX Master)
2005-03-29 08:00 PM
Re: Add Domain group to local groups...

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



**DONOTDELETE**
(Lurker)
2005-03-30 01:03 PM
Re: Add Domain group to local groups...

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!


Duncman
(Fresh Scripter)
2005-03-30 01:04 PM
Re: Add Domain group to local groups...

...and sorry, I forgot to login