Article

List Full Name of Members of a Specified Group

Author Info

7 November 2008 - 12:42pm
Submitted by: grahamch

article
Reads:

2280

Score:
0
0
 
Comments:

3

Purpose:

A quick and easy way to list all the members of a group object, including the user’s full name, and outputting the list to a csv file. This allows you to provide the list of real names to a manager/supervisor/<fill in the blank> and not expect them to recognize people by their username.

This vbscript requires nwdirq.dll and nwusrgrp.ocx from the active_ndap NDK (http://developer.novell.com/wiki/index.php/Activex_ndap) to be registered on the workstation.

This script will list all the users in a specified Group (the output is Full Name, OU the account is in, username) to a csv file.

set oFso = createobject("scripting.filesystemobject")
set oNWDirq = createobject("nwdirquerylib.nwdirquery.1")
set oNWUsrGrp = createobject("nwusrgrplib.nwusrgrpctrl.1")

cOutput1 = "c:\temp\GroupMembership-"
cOutput2 = ".csv"

sGroup = inputbox("What is the name of the group that you would like to list the members of?")

oNWUsrGrp.fullname = "NDS:\\---your tree name---\---your O name---\---OU that contains your groups---"

'*** Error trapping to catch cases where the group does not exist
'*** in the branch that the user selected
on error resume next
set oGroup = oNWUsrGrp.groups.item(oNWUsrGrp.fullname & "\" & sGroup)

if err.number = 52958 then
   msgbox "The group does not exist in the " & sBranch & " branch of the tree."
   wscript.quit
else
   if err.number <> 0 then '***Catch any other errors and display the error number and description
      msgbox err.number & " - " & err.description
      wscript.quit
   end if
end if
on error goto 0 '***Turns of "on error resume next"

set oOutput = oFso.opentextfile(cOutput1 & sBranch & "-" & sGroup & cOutput2, 2, true)

oOutput.writeline "Branch & Group Name,Full Name,OU,Account"
oOutput.writeline sBranch & " - " & sGroup

set oGroupMembers = oGroup.groupmembers
for each user in oGroupMembers
   sOU = replace(user, "\" & user.shortname, "")
   oNWUsrGrp.fullname = sOU
   set oUser = oNWUsrGrp.users.item(oNWUsrGrp.fullname & "\" & user.shortname)
   sOU = replace(sOU, "NDS:\\---your tree name---\", "")
   on error resume next
   if isnull(oUser.fullname) then
      if isnull(oUser.firstname) then
         oOutput.writeline ",**** " & oUser.lastname & "," & sOU & "," & user.shortname
      else
         oOutput.writeline "," & oUser.firstname & " " & oUser.lastname & "," & sOU & "," & user.shortname
      end if
   else
      oOutput.writeline "," & oUser.fullname & "," & sOU & "," & user.shortname
   end if

   if err.number <> 0 then
'      msgbox err.number & vbcrlf & err.description
      err.clear
   end if
   on error goto 0
next
oOutput.close
msgbox "Done"


Author Info

7 November 2008 - 12:42pm
Submitted by: grahamch




User Comments

help

Submitted by anonymous (not verified) on 14 November 2008 - 12:03pm.

need the same script but for all workstation obj in an ou.

RE: need the same script but for all workstation obj in an ou.

Submitted by superjoe on 19 November 2008 - 4:31pm.

I modified a similar script (doesn't use NDK) to find your workstation stuff:

* my script looks for an input text file listing the DNs of the workstations (use ICE to get this)
* My script assumes the input file is delimited with a dollar sign "$" and takes the very first value/column (no need to take this into account if your text file is simply a list of DNs and nothing else)
* My script constantly spits stuff to the screen because I like to see what is happening.
* Because of this, my script should be ran with "cscript" rather than "wscript" (ie at the command line)
* Type "cscript Script.vbs" at the command line to see the sysntax

* The script looks much better when formated with tabs, but those got lost when I pasted it in this forum


' ** Check for help request **
ShowManScreen = False
if (Wscript.Arguments.Count <> 8) then
ShowManScreen = True
Else
if ((lcase(WScript.Arguments(0))) = "h") or ((lcase(WScript.Arguments(0))) = "help") or (WScript.Arguments(0) = "?") or ((lcase(WScript.Arguments(0))) = "man") then
ShowManScreen = True
End if
End if

WSCript.Echo "###############################################"
WSCript.Echo "###############################################"
WSCript.Echo "### ###"
WSCript.Echo "### User wMUserHistory to Output file ###"
WSCript.Echo "### ###"
WSCript.Echo "###############################################"
WSCript.Echo "###############################################"
WSCript.Echo ""

if ShowManScreen then
WSCript.Echo ""
WSCript.Echo "This Script Looks reads the INPUT file of Workstation object DNs"
WSCript.Echo ""
WSCript.Echo "It checks LDAP the wMUserHistory attribute."
WSCript.Echo "Checks to make sure the attributes are the right objectClass (groupOfNames) or (organizationalRole)."
WSCript.Echo "If they are the right objectClass, then it adds a line to the output file"
WSCript.Echo ""
WSCript.Echo ""
WSCript.Echo "USE THE FOLLOWING SYNTAX:"
WSCript.Echo ""
WSCript.Echo "cscript csv2LDIF.vbs A B C D E F G H"
WSCript.Echo ""
WSCript.Echo " A = Path, name, and extension of the CSV input file (example: c:\INPUT.csv)"
WSCript.Echo " B = LDAP Username (example: cn=admin,o=acme)"
WSCript.Echo " C = LDAP password (example: password)"
WSCript.Echo " D = LDAP Server IP (example: 10.10.10.1)"
WSCript.Echo " E = LDAP Server port (example: 389)"
WSCript.Echo " F = LDAP Secure 1=yes, 0=no (example: 0)"
WSCript.Echo " G = Path, name, and extension of the output file (example: c:\OUTPUT.csv)"
WSCript.Echo " H = Path, name, and extension of the Error Log output file (example: c:\ERRORLOG.csv)"
WSCript.Echo ""
WSCript.Echo "example: cscript Script.vbs c:\INPUT.csv cn=admin,o=acme password 10.10.10.1 389 0 c:\OUTPUT.csv c:\ERRORLOG.csv"
WSCript.Echo ""
WSCript.Echo ""
WSCript.Echo "See this screen with the following parameters:"
WSCript.Echo "cscript reconcile.vbs ?"
WSCript.Echo "cscript reconcile.vbs h"
WSCript.Echo "cscript reconcile.vbs help"
WSCript.Echo "cscript reconcile.vbs man"
WSCript.Echo ""

Else

' ##### BEGIN Variables #####
Dim Starttime

Dim ERRORLOG_Output_oFilesys
Dim ERRORLOG_Output_oFiletxt
Dim ERRORLOG_OUTPUT_FILE

Dim OUTPUT_Output_oFilesys
Dim OUTPUT_Output_oFiletxt
Dim OUTPUT_OUTPUT_FILE
Dim SinglewMUserHistory

Dim CSV_LineNumber
Dim CSV_CurrentLine
Dim CSV_DN
Dim CSV_oFSO
Set CSV_oFSO = CreateObject( "Scripting.FileSystemobject" )
Dim CSV_INPUT_FILE
Dim CSV_oStream
dim CSV_Deliminator

dim LDAP_Admin_Username
dim LDAP_Admin_Password
dim LDAP_Server_IP
dim LDAP_Server_Port
dim LDAP_root
dim LDAP_Secure

dim objLDAP
Dim LDAP_Result
dim LDAP_queryDN
dim LDAP_Server_LDAPIPPortAndQuery

dim objLDAP2
Dim LDAP_Result2
dim wMUserHistory
dim LDAP_Server_LDAPIPPortAndQuery2

dim LookingForClass

dim error_count
dim WorkforceID
dim Mailstop
dim GroupDNarray
dim wMUserHistoryCN
Dim logindisabled
Dim accountExpired
Dim logintime
Dim Surname
Dim Givenname
dim fullName

' ##### END Variables #####

' ##### BEGIN Initial population of variables #####

WSCript.Echo "Setting Variables...."
WSCript.Echo ""

CSV_INPUT_FILE = WScript.Arguments(0)
WSCript.Echo "Input CSV file Set to", CSV_INPUT_FILE, "."

LDAP_Admin_Username = WScript.Arguments(1)
WSCript.Echo "LDAP Username Set to", LDAP_Admin_Username

LDAP_Admin_Password = WScript.Arguments(2)
WSCript.Echo "LDAP Password Set"

LDAP_Server_IP = WScript.Arguments(3)
WSCript.Echo "LDAP Server IP Set to", LDAP_Server_IP

LDAP_Server_Port = WScript.Arguments(4)
WSCript.Echo "LDAP Server Port Set to", LDAP_Server_Port

LDAP_Secure = WScript.Arguments(5)
WSCript.Echo "LDAP Server Port Set to", LDAP_Secure

OUTPUT_OUTPUT_FILE = WScript.Arguments(6)
WSCript.Echo "OUTPUT output file Set to", OUTPUT_OUTPUT_FILE

ERRORLOG_OUTPUT_FILE = WScript.Arguments(7)
WSCript.Echo "ERRORLOG output file Set to", ERRORLOG_OUTPUT_FILE

LookingForClass = "Workstation"
LookingForClass2 = "Computer"
LookingAtAttribute = "wMUserHistory"
SinglewMUserHistory = "False"

CSV_Deliminator = "$"
error_count = 0
CSV_LineNumber = 0
Starttime = Now

WSCript.Echo ""
WSCript.Echo "Done."
WSCript.Echo ""

' ##### END Initial population of variables #####

' ##### BEGIN Create Output Files #####

Set ERRORLOG_Output_oFilesys = CreateObject("Scripting.FileSystemObject")
Set ERRORLOG_Output_oFiletxt = ERRORLOG_Output_oFilesys.CreateTextFile(ERRORLOG_OUTPUT_FILE,8, FALSE)

Set OUTPUT_Output_oFilesys = CreateObject("Scripting.FileSystemObject")
Set OUTPUT_Output_oFiletxt = OUTPUT_Output_oFilesys.CreateTextFile(OUTPUT_OUTPUT_FILE,8, FALSE)

' ##### END Create Output Files #####

' ##### BEGIN Shared code #####

' ##### END Shared code #####

' ##### BEGIN Process Data Data #####

WSCript.Echo "Starttime", Starttime
WSCript.Echo ""
WSCript.Echo "******************************************************************"
WSCript.Echo "Begin processing Data from", CSV_INPUT_FILE,"..."
WSCript.Echo "******************************************************************"
WSCript.Echo ""
Set CSV_oStream = CSV_oFSO.OpenTextFile( CSV_INPUT_FILE )

' ** If there is a header in the input file, then you would need to skip the header
' CSV_oStream.SkipLine

Do While CSV_oStream.AtEndOfStream = False

WSCript.Echo "*********************************************************************"
WSCript.Echo ""

CSV_DN = ""
CSV_CurrentLine = ""
LDAP_QueryDN = ""
Mailstop = ""
WorkforceID = ""
AccountDisabled = ""
AccountExpired = ""
CSV_CurrentLine = CSV_oStream.ReadLine
CSV_DN = CSV_CurrentLine
LDAP_QueryDN = ((Split(CSV_DN, "$"))(0))
CSV_LineNumber = CSV_LineNumber + 1

WSCript.Echo "Processing Record #", CSV_LineNumber
WScript.Echo ""
WSCript.Echo " ", "INPUT DN:", LDAP_QueryDN
WSCript.Echo ""
WSCript.Echo " ", "Searching", LDAP_Server_IP, "for", LDAP_QueryDN
WSCript.Echo " ", "to get wMUserHistory attibute"

LDAP_Server_LDAPIPPortAndQuery = "LDAP://" + LDAP_Server_IP + ":" + LDAP_Server_Port + "/" + LDAP_queryDN

Set objLDAP = GetObject("LDAP:")
On Error Resume Next
Set LDAP_Result = objLDAP.OpenDSObject(LDAP_Server_LDAPIPPortandQuery, LDAP_Admin_Username , LDAP_Admin_Password , LDAP_Secure)

if Err Then
WSCRipt.Echo "ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR"
WSCRipt.Echo "ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR"
WSCRipt.Echo "ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR"
WScript.Echo "ERROR ERROR"
WSCript.Echo "ERROR LDAP1 says: ERROR"
WScript.Echo "ERROR ERROR"
WSCript.Echo "ERROR Huh, what kinda' crazy talk was that? ERROR"
WScript.Echo "ERROR ERROR"
WSCript.Echo "ERROR No hablo español ERROR"
WScript.Echo "ERROR Je ne parle pas français ERROR"
WScript.Echo "ERROR Nihongo wo hanasemasen ERROR"
WSCript.Echo "ERROR ERROR"
WSCript.Echo "ERROR Ain't gonna' tell you nothin' sucka' ERROR"
WScript.Echo "ERROR ERROR"
WSCRipt.Echo "ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR"
WSCRipt.Echo "ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR"
WSCRipt.Echo "ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR"
Err.Clear
WSCript.Echo ""
ERRORLOG_Output_oFiletxt.WriteLine (CSV_CurrentLine & (CSV_Deliminator) & "can't query this object")
WSCript.Echo ""
WSCript.Echo ERRORLOG_OUTPUT_FILE,"has been updated."
WSCript.Echo ""
WSCript.Echo "*********************************************************************"
On Error GoTo 0
error_count = error_count +1
Else
On Error GoTo 0
On Error Resume Next
For Each objPropValue in LDAP_Result.wMUserHistory
if Err Then
Err.Clear
wMUserHistory = (LDAP_Result.wMUserHistory)
SinglewMUserHistory = "True"
If Err Then
wMUserHistory = ""
SinglewMUserHistory = "False"
End IF
If wMUserHistory = "" Then
WSCRipt.Echo "ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR"
WSCRipt.Echo "ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR"
WSCRipt.Echo "ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR"
WScript.Echo "ERROR ERROR"
WSCript.Echo "ERROR LDAP2 says: ERROR"
WScript.Echo "ERROR ERROR"
WSCript.Echo "ERROR Huh, what kinda' crazy talk was that? ERROR"
WScript.Echo "ERROR ERROR"
WSCript.Echo "ERROR No hablo español ERROR"
WScript.Echo "ERROR Je ne parle pas français ERROR"
WScript.Echo "ERROR Nihongo wo hanasemasen ERROR"
WSCript.Echo "ERROR ERROR"
WSCript.Echo "ERROR Ain't gonna' tell you nothin' sucka' ERROR"
WScript.Echo "ERROR ERROR"
WSCRipt.Echo "ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR"
WSCRipt.Echo "ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR"
WSCRipt.Echo "ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR"
Err.Clear
WSCript.Echo ""
ERRORLOG_Output_oFiletxt.WriteLine (CSV_CurrentLine & (CSV_Deliminator) & "Nihongo wo hanasemasen - can't query this object's wMUserHistory attribute, probably because it has no wMUserHistorys")
WSCript.Echo ""
WSCript.Echo ERRORLOG_OUTPUT_FILE,"has been updated."
WSCript.Echo ""
WSCript.Echo "*********************************************************************"
On Error GoTo 0
error_count = error_count +1
Exit For
End if
Else
wMUserHistory = (objPropValue)
End if
' Else
WSCript.Echo ""
WSCript.Echo " ","wMUserHistory=",objPropValue
WSCript.Echo ""

'** Check to see if it is the right class

WSCript.Echo ""
WSCript.Echo " "," ", "SEARCHING", LDAP_Server_IP, "FOR", wMUserHistory
WSCript.Echo " "," ", "TO SEE IF objectClass =", LookingForClass, "or", LookingForClass2
WSCript.Echo ""
LDAP_Server_LDAPIPPortAndQuery2 = "LDAP://" + LDAP_Server_IP + ":" + LDAP_Server_Port + "/" + wMUserHistory
Set objLDAP2 = GetObject("LDAP:")
On Error Resume Next
Set LDAP_Result2 = objLDAP2.OpenDSObject(LDAP_Server_LDAPIPPortandQuery2, LDAP_Admin_Username , LDAP_Admin_Password , LDAP_Secure)
if Err Then
WSCRipt.Echo "ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR"
WSCRipt.Echo "ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR"
WSCRipt.Echo "ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR"
WScript.Echo "ERROR ERROR"
WSCript.Echo "ERROR LDAP3 says: ERROR"
WScript.Echo "ERROR ERROR"
WSCript.Echo "ERROR Huh, what kinda' crazy talk was that? ERROR"
WScript.Echo "ERROR ERROR"
WSCript.Echo "ERROR No hablo español ERROR"
WScript.Echo "ERROR Je ne parle pas français ERROR"
WScript.Echo "ERROR Nihongo wo hanasemasen ERROR"
WSCript.Echo "ERROR ERROR"
WSCript.Echo "ERROR Ain't gonna' tell you nothin' sucka' ERROR"
WScript.Echo "ERROR ERROR"
WSCRipt.Echo "ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR"
WSCRipt.Echo "ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR"
WSCRipt.Echo "ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR*ERROR"
Err.Clear
WSCript.Echo ""
ERRORLOG_Output_oFiletxt.WriteLine (CSV_CurrentLine & (CSV_Deliminator) & "can't query" & wMUserHistory & "to see if it is a group")
WSCript.Echo ""
WSCript.Echo ERRORLOG_OUTPUT_FILE,"has been updated."
WSCript.Echo ""
WSCript.Echo "*********************************************************************"
On Error GoTo 0
error_count = error_count +1
Else
On Error GoTo 0

On Error Resume Next
WorkforceID = LDAP_Result.workforceID
if err then
WorkforceID = ""
Err.Clear
else
if TypeName(WorkforceID) <> "String" then
WorkforceID = ""
end if
end if
On Error GoTo 0

On Error Resume Next
workforceid = LDAP_Result.workforceid
if err then
workforceid = "Error: No workforceid Defined"
Err.Clear
end if
On Error Goto 0

On Error Resume Next
logindisabled = LDAP_Result.logindisabled
if (err) then
logindisabled = "*FALSE*"
Err.Clear
end if
On Error Goto 0

On Error Resume Next
surname = LDAP_Result.sn
if (err) or (TypeName(surname) <> "String") then
surname = ""
Err.Clear
end if
On Error Goto 0

On Error Resume Next
GivenName = LDAP_Result.GivenName
if (err) or (TypeName(GivenName) <> "String") then
GivenName = ""
Err.Clear
end if
On Error Goto 0

On Error Resume Next
logintime = LDAP_Result.logintime
if (err) then
logintime = ""
Err.Clear
end if
On Error Goto 0

On Error Resume Next
fullName = LDAP_Result.fullName
if (err) or (TypeName(fullName) <> "String") then
fullName = ""
Err.Clear
end if
On Error Goto 0

For Each objPropValue3 in LDAP_Result2.ObjectClass
wscript.Echo " "," "," ","objectClass = ", objPropValue3
wscript.echo ""
if (objPropValue3 = (LookingForClass)) or (objPropValue3 = (LookingForClass2))then
wscript.Echo " "," "," "," ","CORRECT objectClass"
wscript.echo ""
GroupDNarray = Split(wMUserHistory, ",")
wMUserHistoryCN = GroupDNarray(0)
wscript.Echo " "," "," "," "," ","Writing to output file"
wscript.echo ""
wscript.echo " "," "," "," "," "," ","INPUT:",CLDAP_QueryDN
Wscript.Echo " "," "," "," "," "," ","wMUserHistory:",wMUserHistory
Wscript.Echo " "," "," "," "," "," ","wMUserHistory CN:",wMUserHistoryCN
Wscript.Echo " "," "," "," "," "," ","wMUserHistory workforceid:",workforceid
Wscript.Echo " "," "," "," "," "," ","wMUserHistory Disabled:",logindisabled
Wscript.Echo " "," "," "," "," "," ","wMUserHistory Expired:",accountExpired
Wscript.Echo " "," "," "," "," "," ","wMUserHistory Given Name:",givenname
Wscript.Echo " "," "," "," "," "," ","wMUserHistory Surname:",surname
Wscript.Echo " "," "," "," "," "," ","wMUserHistory Full Name:",fullname
Wscript.Echo " "," "," "," "," "," ","wMUserHistory logintime:",logintime

OUTPUT_Output_oFiletxt.WriteLine ((wMUserHistory) & (CSV_Deliminator) & (wMUserHistoryCN) & (CSV_Deliminator) & (workforceid) & (CSV_Deliminator) & (logindisabled) & (CSV_Deliminator) & (givenName) & (CSV_Deliminator) & (surName)& (CSV_Deliminator) & (fullName) & (CSV_Deliminator) & (logintime) & (CSV_Deliminator) & (objPropValue3) & (CSV_Deliminator) & (CSV_CurrentLine))
Exit For
else
wscript.Echo " "," "," "," ","WRONG objectClass"
wscript.echo ""
end if
Next
End if
' End If
If SinglewMUserHistory = "True" Then
SinglewMUserHistory = "False"
Exit For
End if
Next

WSCript.Echo ""
WSCript.Echo "*********************************************************************"

' objLDAP.CloseDSObject

End If

Loop

CSV_oStream.Close
ERRORLOG_Output_oFiletxt.Close
OUTPUT_Output_oFiletxt.Close

WSCript.Echo "Done."
WSCript.Echo ""
WSCript.Echo "Started:", Starttime
WSCript.Echo "Finished:", Now
WSCript.Echo ""
WSCript.Echo "Errors:",error_count

End If

' ##### END Process Data #####

Control is not initialized

Submitted by admingk on 5 January 2009 - 12:24pm.

Never have used NDK until now, and I am positive that the files are registered, so any ideas as to why I get the message "52757 - Control is not initialized"

© 2009 Novell, Inc. All Rights Reserved.