Get all of the users in a group on the domain
Keywords: wntUserInfo wntListGroups wntMemberList
;This script pulls all of the users in a group on the domain.
;The most unique feature is that it can pull users that are in
;global groups included in a specified local group
ErrorMode(@Notify)
;DebugOn = "YES"
DebugOn = "NO"
AddExtender("WWWNT34I.DLL")
GOSUB AskParameters
GOSUB GetUsers
GOSUB Output
EXIT
;*************************************************************************
:AskParameters
;Any active parameters can go here.
;This section currently defiunes the server used to process commands,
;the group to fucus on, and the sort field
LocalORGlobal = "LOCAL"
;LocalORGlobal = "GLOBAL"
LocalORGlobal = AskItemList(" Choose group type to focus on", "LOCAL%@tab%GLOBAL" , @tab , @unsorted , @single)
LogonServer = wntUserInfo(3)
UseLogonServer = AskYesNo( "Domain Controller Verification" , "The default domain controller for this system is:%@crlf%%LogonServer%%@crlf%%@crlf%Should this DC be used to process user requests?" )
IF UseLogonServer == @NO
servers = wntServerList("","",24) ; Gets the BDC's and the PDC
server = AskItemList("Choose a server to process network requests.",servers,@tab,@sorted,@single)
ELSE
server = "\\%LogonServer%"
ENDIF
IF LocalORGlobal == "LOCAL"
localgroups=wntListGroups(server,@LOCALGROUP)
group = AskItemList("Local Groups",localgroups,@tab,@sorted,@single)
ENDIF
IF LocalORGlobal == "GLOBAL"
globalgroups=wntListGroups(server,@GLOBALGROUP)
group = AskItemList("Global Groups",globalgroups,@tab,@sorted,@single)
ENDIF
return
;*************************************************************************
:GetUsers
;This section just pulls a list of the users in the group specified above.
BoxOpen("Processing", "Be patient")
BoxText("Getting list of users from %server%,%@CRLF%%@CRLF%Please wait")
IF LocalORGlobal == "LOCAL"
Users=wntMemberList(server,group,@LOCALGROUP)
n = ItemCount(users, @TAB)
GlobalGroups = ""
ItemsRemoved = 0
For UserNum = 1 to n ;Pull groups out of the "users" list. Add them to a new list of Global Groups.
BoxText("Checking list of users for Global Groups,%@CRLF%%@CRLF%Working on item %UserNum% of %n%")
ListItem = UserNum - ItemsRemoved
UserName = ItemExtract( ListItem , Users , @TAB )
GroupTest = wntUserExist( "%server%" , "%UserName%" )
if GroupTest == @False ;If this is true, then this item is valid user, and will be used later.
GlobalGroups = ItemInsert( "%UserName%" , -1 , GlobalGroups , @TAB )
Users = ItemRemove ( ListItem , Users , @TAB )
ItemsRemoved = ItemsRemoved + 1
endif
next
NumIncludedGroups = ItemCount( GlobalGroups , @TAB )
if NumIncludedGroups > 0
IncludedUsers = ""
for IncludedGroupNum = 1 to NumIncludedGroups ;Make a list of users from ALL of the included groups.
BoxText("Creating list of users from the included Global Groups,%@CRLF%%@CRLF%Working on group %IncludedGroupNum% of %NumIncludedGroups%")
IncludedGroup = ItemExtract( IncludedGroupNum , GlobalGroups , @TAB )
TmpUsers = wntMemberList( server , IncludedGroup , @GLOBALGROUP )
IF strlen(IncludedUsers) < 1 ;This just handles the first entry in the list so that there isn't a blank entry at one end of the list.
IncludedUsers = strcat( TmpUsers )
else
IncludedUsers = strcat( TmpUsers , @TAB , IncludedUsers )
endif
next
if DebugOn == "YES"
BoxShut()
AskItemList("Un-sorted List of Included Users", IncludedUsers , @tab , @unsorted , @single)
BoxOpen("Processing", "Be patient")
endif
n = ItemCount( IncludedUsers , @TAB )
BoxText("Sorting the list of %n% included users,%@CRLF%%@CRLF%This may take some time.")
IncludedUsers = ItemSort( IncludedUsers , @tab )
if DebugOn == "YES"
BoxShut()
AskItemList("Sorted List of Included Users", IncludedUsers , @tab , @unsorted , @single)
BoxOpen("Processing", "Be patient")
endif
UniqueIncludedUsers = ""
UniqueIncludedUser = ""
for x = 1 to n ;Loop through the list again, compareing one item to the next. Only write unique entries to the final list.
BoxText("Removeing duplicates from the list of included users,%@CRLF%%@CRLF%Working on item %x% of %n%")
IncludedUserName = ItemExtract( x , IncludedUsers , @TAB )
if "%UniqueIncludedUser%" <> "%IncludedUserName%"
IF strlen(UniqueIncludedUsers) < 1 ;This just handles the first entry in the list so that there isn't a blank entry at one end of the list.
UniqueIncludedUsers = strcat( IncludedUserName )
else
UniqueIncludedUsers = strcat( UniqueIncludedUsers , @TAB , IncludedUserName )
endif
UniqueIncludedUser = IncludedUserName
endif
next
if DebugOn == "YES"
BoxShut()
AskItemList("List of Unique Included Users", UniqueIncludedUsers , @tab , @unsorted , @single)
; BoxOpen("Processing", "Be patient")
endif
n = ItemCount( UniqueIncludedUsers , @TAB )
BoxShut()
IF AskYesNo("Included items found","The LOCAL group %group% includes%@crlf%%NumIncludedGroups% GLOBAL group(s) that contain a total of%@crlf%%n% additional users.%@crlf%%@crlf%Should these additional users be included?") == @YES
BoxOpen("Processing", "Be patient")
AllUsers = strcat( Users , @TAB , UniqueIncludedUsers )
if DebugOn == "YES"
BoxShut()
AskItemList("Un-sorted list of Users", AllUsers , @tab , @unsorted , @single)
BoxOpen("Processing", "Be patient")
endif
n = ItemCount( AllUsers , @TAB )
BoxText("Sorting the list of %n% users,%@CRLF%%@CRLF%This may take some time.")
AllUsers = ItemSort( AllUsers , @tab )
if DebugOn == "YES"
BoxShut()
AskItemList("Sorted List of users", AllUsers , @tab , @unsorted , @single)
BoxOpen("Processing", "Be patient")
endif
UniqueUsers = ""
UniqueUser = ""
for x = 1 to n ;Loop through the list again, compareing one item to the next. Only write unique entries to the final list.
BoxText("Removeing duplicates from the list of %n% users,%@CRLF%%@CRLF%Working on item %x% of %n%")
Tmp_User = ItemExtract( x , AllUsers , @TAB )
if "%UniqueUser%" <> "%Tmp_User%"
IF strlen(UniqueUsers) < 1 ;This just handles the first entry in the list so that there isn't a blank entry at one end of the list.
UniqueUsers = strcat( Tmp_User )
else
UniqueUsers = strcat( UniqueUsers , @TAB , Tmp_User )
endif
UniqueUser = Tmp_User
endif
next
if DebugOn == "YES"
BoxShut()
AskItemList("List of unique users", UniqueUsers , @tab , @unsorted , @single)
endif
Users = strcat( UniqueUsers )
ENDIF
endif
ENDIF
IF LocalORGlobal == "GLOBAL"
Users=wntMemberList(server,group,@globaLGROUP)
ENDIF
BoxShut()
return
;*************************************************************************
:Output
AskItemList(" Here are the users in the %LocalORGlobal% group %group%", Users , @tab , @unsorted , @single)
return
;*************************************************************************
Article ID: W13781
Filename: Get all of the users in a group on the domain.txt