WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Network

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

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
File Created: 2010:06:03:11:12:28
Last Updated: 2010:06:03:11:12:28