This script retrieves all the members of a supplied Confluence group, and then retrieves the timestamp of the last time that user logged in to Confluence.
As you can see from the code below, we’re working with three classes. The usual Component Locator, the Login Manager, and the Group Manager.
After telling the Component Locator to fetch the Login Manager and Group Manager, we feed the name of a group to the getGroup() method of the Group Manager. This returns a group as an object.
We also need to define an array that will hold our results. This is because the ScriptRunner console doesn’t easily provide output; you can’t simply throw in a System.out.println(). If you try to use the log as output, it truncates after 300 results. Instead we need to add the results to an array, and then return the array at the end.
The group object we created is passed to the getMemberNames() method of the group manager, which unsurprisingly returns the names of group members.
Next a for-each statement takes each user in the group and uses the getLoginInfo of the Login Manager to get the login information of each user.
Finally, within that loop we add the last successful login date of the user to the array, along with the username. The array is printed when the loop finishes.
//These are the libraries we'll need
def loginManager = ComponentLocator.getComponent(LoginManager)
//We'll need the login manager to get the login info of the users
def groupManager = ComponentLocator.getComponent(GroupManager)
//We'll need the group manager to get all the members of a group
def groupname = groupManager.getGroup("<group name>")
//The group manager needs a group object as input, not just a string
def array = 
//In order to get the results, we need an array to hold them
def group = groupManager.getMemberNames(groupname)
//Tell the group manager to get the members of the given group
//For each user in the group
def loginDetails = loginManager.getLoginInfo(user)
//Fetch the login details of the user
array += ("Username: " + user + " Last login date: " + loginDetails.getLastSuccessfulLoginDate()+"<br>")
//Add the user details to the array
//Print the array