You can now vote for scripts to help people know if they're useful or not. Login or create an account to vote!


Deactivate inactive users in Confluence


Maintain your Confluence instance by deactivating users based on the time since they last logged in.


As an administrator, I have the responsibility of maintaining an accurate and up-to-date list of who is using the Atlassian tools, to avoid paying for users that are not getting value from the products. I want to deactivate all users that haven't logged in for the last three months. This script allows me to find all users that haven't logged in for the specified time, remove them from the confluence-users group, and add them to a deactivated user group, thus reducing my licensed user count.

Good to Know

  • In this example, we consider both successful and failed login attempts, though you can adjust it to match your use case.


  • Confluence Confluence (6.6 - 7.10)
  • ScriptRunner for Confluence ScriptRunner for Confluence (6.21.0)
import import com.atlassian.confluence.user.UserAccessor import com.atlassian.sal.api.component.ComponentLocator import com.atlassian.user.GroupManager import java.time.LocalDateTime import java.time.ZoneId def groupManager = ComponentLocator.getComponent(GroupManager) def loginManager = ComponentLocator.getComponent(LoginManager) def userAccessor = ComponentLocator.getComponent(UserAccessor) def inactiveGroup = groupManager.getGroup("Deactivated users") ?: groupManager.createGroup("Deactivated users") def confluenceUsersGroup = groupManager.getGroup('confluence-users') def users = groupManager.getMemberNames(confluenceUsersGroup) users.each { userName -> def user = userAccessor.getUserByName(userName) if (user) { "Inspecting $ to determine whether user should be deactivated" def loginInfo = loginManager.getLoginInfo(user) def lastSuccessfulDate = convertDate(loginInfo?.lastSuccessfulLoginDate) def lastFailedDate = convertDate(loginInfo?.lastFailedLoginDate) def threeMonthsAgo = if (lastFailedDate?.isBefore(threeMonthsAgo) && lastSuccessfulDate?.isBefore(threeMonthsAgo)) { "User ${} last successuflly logged in ${lastSuccessfulDate} and last failed to login on ${lastFailedDate}" "Removing user ${} from confluence-users" groupManager.removeMembership(confluenceUsersGroup, user) "Add user ${} to the group: 'Deactivated Users'" groupManager.addMembership(inactiveGroup, user) "Deactivating user ${}" userAccessor.deactivateUser(user) } } } /** * Note: In the latest versions of ScriptRunner, you can simply use to convert the Date object to a LocalDateTime, as we have upgraded to Groovy 2.5. This convenience method is here for backward compatibility only. * @param date * @return */ private static LocalDateTime convertDate(Date date) { date?.toInstant()?.atZone(ZoneId.systemDefault())?.toLocalDateTime() }
Discovered an issue? Report it here

Suggested for you