'====================================================================
'= Show NetWare Server Groups and Members VBScript sample - Copyright © 2007, Dave Moats
'=
'= This sample is provided 'as-is', without any express or implied warranty.
'= In no event will the authors be held liable for any damages arising from
'= the use of this sample code.
'=
'= Permission is granted to anyone to use this sample code for any purpose,
'= including commercial applications, subject to the following restrictions:
'=
'= The origin of this code must not be misrepresented;
'=       you must not claim that you wrote the original code.
'=       If you use this code, an acknowledgment in the
'=       documentation is requested - shown below:
'=
'= Portions Copyright © 2007, Dave Moats (http://www.davemoats.com/).
'=
'====================================================================
'====================================================================
'==
'== nwGroups.vbs - script to list all the groups and their members
'==                         on a Server
'==
'====================================================================
set fso = createobject ( "Scripting.FileSystemObject")

'====================================================================
'== Get the NetWare Server and the output file
'====================================================================
if wscript.arguments.count = 0 then
   wscript.echo ( "Usage: nwGroups.vbs <Server> <Path to Ouput file>")
   srvPath = inputbox ( "Enter the server that you want to list the groups for:")
   outPath = inputbox ( "Enter the path to the output file:")
elseif wscript.arguments.item ( 0) = "/?" Or wscript.arguments.item ( 0) = "-?" then
   wscript.echo ( "Usage: nwGroups.vbs <Server> <Path to Ouput file>")
   wscript.quit ( )
else
   svrPath = wscript.arguments.item ( 0)
   outPath = wscript.arguments.item ( 1)
end if

'====================================================================
'== validate that there was something passed to the script
'====================================================================
if svrPath = "" or outPath = "" then
   wscript.echo ( "There were not enough arguments passed to the script")
   wscript.echo ( "Usage: nwGroups.vbs <Server> <Path to Ouput file>")
   wscript.quit ( )
end if

'====================================================================
'== Open the results file
'====================================================================
set outFile = fso.createtextfile ( outPath)

'====================================================================
'== turn off the wscript error handling - so the script can trap
'== any errors
'====================================================================
on error resume next

'====================================================================
'== Try to bind to the Netware Server we are interested in
'====================================================================
svrPath = "NWCOMPAT://" & svrPath
svrFilter = array ( "Group")
set srvObj = getobject ( svrPath)

'====================================================================
'== See if bound to the server without errors
'====================================================================
if err.number = 0 then

      '================================================================
      '== Apply the filter to the returned object
      '================================================================
      srvObj.filter = svrFilter
     
      '================================================================
      '== Go through the list of groups displaying the members
      '================================================================
      for each nwGrp in srvObj

            outFile.writeline ( "Group - " & stripProvider ( nwGrp.ADsPath))

            '============================================================
            '== Check each member of the group - if it is a group
            '== enumerate it
            '============================================================
            for each member in nwGrp.members
     
               if member.Class= "Group" then
                     outFile.writeline ( "    Group - " & stripProvider ( member.ADsPath) )
                     enumGroup member.ADsPath
               else
                     outFile.writeline ( "    User - " & stripProvider ( member.ADsPath) )
               end if
     
            next
     
            outFile.writeline ( " ")
     
      next
     
else

      '================================================================
      '== had a problem binding to the server so let's see what happened
      '================================================================
      outFile.writeline ( "Unable to attach to: " & svrPath & " Error Information: " & _
                                    err.number & " - " & err.description )

endif
     
'====================================================================
'== dump the reference to the server
'====================================================================
set srvObj = nothing

'====================================================================
'== Clean up the out file reference and the file system object
'====================================================================
outFile.close
set outFile = nothing

set fso = nothing

wscript.quit ( )

'====================================================================
'== sub routine to enumerate group's members
'====================================================================
sub enumGroup ( groupPath )

   set nestedGroup = getobject ( groupPath)
   '====================================================================
   '== Go through the list of groups displaying the members
   '====================================================================
   for each member in nestedGroup.members
      outFile.writeline ( "             User - " & stripProvider ( member.ADsPath) )
   next
  
   set nestedGroup = nothing

sub

'====================================================================
'== function used to strip the ADSI provider from the ADsPath
'====================================================================
function stripProvider ( objPath )

   i = instr ( 1, objPath, "/" )

   Temp = mid ( objPath, i+2, len ( objPath) )

   stripProvider = Temp

function


Copyright © 2005 - 2013 Dave Moats.  All rights reserved.  Links: Copyright © by their respective owners.
NO WARRANTIES EXTENDED.  Void where prohibited by law.  Please report any issues or broken links.
You may link to this site freely from your own site.  You may quote from this site, but please include a link to the original source on the originating site.