Page 1 of 1 1
Topic Options
#120315 - 2004-05-28 01:27 AM How to check if domain group is in local admin grp
Ryan Dao Offline
Fresh Scripter

Registered: 2003-03-09
Posts: 45
Hi,
I'm trying to find a way to check if a global group is in the local admin group and if not add it. Tried script below but no thing happens. I'm still on NT domain but will be running script on Win2k machines. Thx

http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=116003&Main=115874

Top
#120316 - 2004-05-28 03:01 AM Re: How to check if domain group is in local admin grp
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I tested the code and it works as expected. Maybe you botched it.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#120317 - 2004-05-28 04:59 AM Re: How to check if domain group is in local admin grp
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Ryan,

Supplied code by Bryce worked for me too. Here is a minor revision. Make sure you're running KiXtart 4.22

Code:
Break On
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
 
Dim $DomainGroups[0],$grouptoadd,$Obj,$GroupObj,$i
 
$grouptoadd = @DOMAIN + "\DomainGroupYouWantToCheckFor"
 
$Obj = GetObject("WinNT://" + @WKSTA + "/Administrators")
$Obj.filter = "group",""
For Each $GroupObj In $Obj.Members
If Split($groupobj.adspath,"/")[3] <> @WKSTA
$DomainGroups[$i] = Split($groupobj.adspath,"/")[2] +"\" + Split($groupobj.adspath,"/")[3]
$i = $i + 1
ReDim Preserve $DomainGroups[$i]
EndIf
Next
 
If AScan($DomainGroups,$GroupToAdd) = -1
$groupToAdd + " was not found in " + $obj.adspath ?
Else
$groupToAdd + " was found in " + $obj.adspath ?
EndIf



 
This code should enumerate the current accounts and groups on the system.

Code:
Break On
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
 
EnumLocalGroups(@DOMAIN,@WKSTA)
 
Function EnumLocalGroups($Domain,$System)
Dim $Array,$colGroups,$objGroup,$objUser,$Flag
$Array = "group",""
$colGroups = GetObject("WinNT://" + $Domain + '/' + $System )
$colGroups.Filter = $Array
$System ?
For Each $objGroup In $colGroups
$objGroup.Name ?
For Each $objUser in $objGroup.Members
CHR(9) + $objUser.Name ?
Next
Next
EndFunction



Then code like this should be able to add to the group if you already have Admin rights on the system.

Code:
Break On
Dim $SO,$AddAdmin
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
 
$AddAdmin = AddToLocalAdmin('computer to add to','Administrators','some domain','some group')
 
Function AddToLocalAdmin($Computer,$GroupToAddTo,$Domain,optional $GroupToAdd,optional $AccountToAdd)
Dim $Group,$User,$Admin,$Err
$Group = GetObject('WinNT://' + $Computer + '/' + $GroupToAddTo + ',group')
If $GroupToAdd<>""
$User = GetObject('WinNT://' + $Domain + '/' + $GroupToAdd + ',group')
EndIf
If $AccountToAdd<>""
$User = GetObject('WinNT://' + $Domain + '/' + $AccountToAdd + ',user')
EndIf
$Group.Add($User.ADsPath)
$Err = @ERROR
$AddToLocalAdmin=$Err
EndFunction
 
Function fnCOMErr($lErr)
If $lErr<0 $lErr=VAL("&"+Right(DecToHex($lErr),4)) EndIf
Exit $lErr
Endfunction


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
1 registered (Henriques) and 2516 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.053 seconds in which 0.027 seconds were spent on a total of 11 queries. Zlib compression enabled.

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