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
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