Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write record for empty AD Group

Status
Not open for further replies.

itsmythg

Technical User
Apr 4, 2001
34
0
0
US
I have this VBscript that searchs AD for specific AD Groups. what it does is list users in group it suppose to print the group name [fh.writeline ";;;Groupname"'] if the group is empty but its printing group name for every group. I'm lost as to how to get it only to print when group is empty.

set fso = createobject("scripting.filesystemobject")
set fh = fso.createtextfile("USERS.txt")


set groupObj = getobject("LDAP://cn=SEC-GS-groupname,ou=securityteam,ou=securitygroups,ou=process,dc=lcc,dc=usairways,dc=com")

count = 0

for each member in groupObj.members
for each member in groupObj.members
WScript.echo Member.displayname & " ; " & Member.lcchirschbadgenum & " ; " & member.samaccountname & " ; " & "groupname"'
fh.writeline member.displayname & " ; " & Member.lcchirschbadgenum & " ; " & member.samaccountname & " ; " & "groupname"'
NEXT
else
fh.writeline ";;;Groupname"'
endif

count = 0

fh.close

wscript.echo "Total members: " & count
 
Seems like you have a 'else ... endif' sentence without a corresponding if ...
I guess you wanted something like this:
Code:
...
Count = 0
For Each member In groupObj.Members
    Count = Count + 1
    fh.WriteLine member.displayname & ";" & member.lcchirschbadgenum & ";" & member.samaccountname & ";" & groupname
Next
If Count = 0 Then
    fh.WriteLine ";;;Groupname"    '
End If
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top