The other day I had to clean up the groups in our Domino Directory. Many groups still contained names of terminated users, they had not been cleaned/maintained properly. We also removed some groups over time, but some of them were still listed as members of other groups.
So I wrote a small Lotuscript agent to perform this cleanup. I am posting it below in case someone needs it. As always: no guarantees, use at your own risk, etc.
Update: As some commenters pointed out, there are some issues with the code. First of all, I was using a view my company added to name.nsf. The view PeopleByFirstName has the following selection formula: SELECT Type = “Person” & TerminationDate=””
The field TerminationDate is one we added to the person document. This field is either blank (for current employees) or contains the date they were terminated (and then they are filtered out of most views).
Also as Christian points out, any groups that contains external users would be clenaed out. In the past when I worked at a company that used mail groups with external users, those groups were kept in a separate (secondary) Domino Directory, names_ext.nsf. So this is something to keep in mind if you choose to use this code.
Finally I have updated the code with a few more lines. It will now ignore server groups, and also get a list of all servers and make sure they are included as group members when the groups are processed.
Thanks for pointing out the problems with the code!
Dim session As New NotesSession Dim db As NotesDatabase Dim view As NotesView Dim doc As NotesDocument Dim userNames List As String Dim groupNames List As String Dim serverNames List As String Dim groups List As NotesDocument Dim tmp As String Dim tmpname As NotesName Set db = New NotesDatabasesession.CurrentDatabase.Server,"names.nsf") '*** Get all existing groups and put in a list Set view = db.getView("Groups") Set doc = view.GetFirstDocument() Do Until doc Is Nothing Set groups(doc.UniversalID) = doc tmp = doc.GetItemValue("ListName")(0) groupNames(tmp) = tmp Set doc = view.GetNextDocument(doc) Loop '*** Get all active users and put in a list Set view = db.getView("PeopleByFirstName") Set doc = view.GetFirstDocument() Do Until doc Is Nothing tmp = doc.GetItemValue("FullName")(0) Set tmpname = New NotesName(tmp) userNames(tmpname.Common) = tmpname.Common Set doc = view.GetNextDocument(doc) Loop '*** Get all servers and put in a list Set view = db.getView("Servers") Set doc = view.GetFirstDocument() Do Until doc Is Nothing tmp = doc.GetItemValue("ServerName")(0) Set tmpname = New NotesName(tmp) serverNames(tmpsname.Common) = tmpname.Common Set doc = view.GetNextDocument(doc) Loop '*** Loop though list of groups and process each one ForAll g In groups '*** Check that not server group If g.GetItemValue("GroupType")(0)<>"4" Then tmp = "" '*** Store existing list of group members in a backup field Call g.ReplaceItemValue("MembersBackup",g.GetItemValue("Members")) '*** Loop through all members of the group ForAll m In g.GetItemValue("Members") Set tmpname = New NotesName(m) '*** If the name is an existing group or an active user, add to list If IsElement(userNames(tmpname.Common)) _ Or IsElement(groupNames(tmpname.Common)) _ Or IsElement(serverNames(tmpname.Common))Then tmp = tmp + tmpname.Canonical + ";" End If End ForAll '*** Write list back to members field Call g.ReplaceItemValue("Members", FullTrim(Split(tmp,";"))) Call g.Save(True,False) End If End ForAll MsgBox "Done!"