I recently had the need to quickly create a CSV list of all the users in an Atlassian Confluence instance.

I quickly wrote a user macro to achieve this, and now I'm sharing it here:


## List Users - Confluence User Macro
##
## Produces a CSV of all members of the `confluence-users` group in Confluence
## Columns: user_key,username,display_name,email
##
## WARNING:
##
## Use very sparingly as this *will* slow down large Confluence instances.
## Yes, it will try to print out 100,000 users if you have that many in the system
##
## I generally remove this user macro after using once and add only when needed.
##
## @noparams

#set($containerManagerClass = $action.class.forName('com.atlassian.spring.container.ContainerManager'))
#set($getInstanceMethod = $containerManagerClass.getDeclaredMethod('getInstance',null))
#set($containerManager = $getInstanceMethod.invoke(null,null))
#set($containerContext = $containerManager.containerContext)

#set($userAccessor = $containerManager.containerContext.getComponent('userAccessor'))
#set($users = $userAccessor.getUsersWithConfluenceAccessAsList() ) ## This method is slow and deprecated
## @see: https://docs.atlassian.com/confluence/latest/com/atlassian/confluence/user/UserAccessor.html#getUsersWithConfluenceAccessAsList()

<h2>Users</h2>

## Drop it in code macro styling
<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<div>
<pre>
<code>user_key,username,display_name,email
#foreach( $user in $users )
${user.key},${user.name},${user.fullName},${user.email}
#end
</code>
</pre>
</div>
</div>

Read the warning in the user macro. It will display all the users. If you have 10 or 100 users, then it will be quick enough, so that's OK. If you have 110,000 users and use this, you're an idiot and your admin permissions should be removed.

Also, this is personally identifiable information, so look after it. Be cautious folks.