Generate a list of space administrators and the space they administrate
Asked by Jaime Romaguera:

Hi,

Would anybody know how I can get a list of space adminstrators and the space they administrate.

Does anybody know of a SQL query or macro plugin.

Why I need is this information so I can supply the helpdesk so they can supply the user who to contact concerning access to the required space.

So you have any ideas it would be great to hear from you. :-)

Many Thanks

Regards

Jaime


Answers:
author: Amalia
body: You can add a user macro through Confluence Admin \> User Macros and add the following template:

```
## This is an example macro## @param Test:title=Test|type=string#set($spaces = $spaceManager.getAllSpaces())#foreach($space in $spaces) 	&lt;h3&gt;Space Name: $space.getName()&lt;/h3&gt;	&lt;table class="confluenceTable"&gt;		#foreach ( $permission in $space.getPermissions() )		#if ($permission.isUserPermission() &amp;&amp; $permission.getType() == "SETSPACEPERMISSIONS")			&lt;tr&gt;			  &lt;td class="confluenceTd"&gt;User&lt;/td&gt;			  &lt;td class="confluenceTd"&gt;$permission.getUserName()&lt;/td&gt;			&lt;/tr&gt;		#elseif ($permission.isGroupPermission() &amp;&amp; $permission.getType() == "SETSPACEPERMISSIONS")			#set ( $group = $permission.getGroup() )			&lt;tr&gt;			  &lt;td class="confluenceTd"&gt;Group&lt;/td&gt;			  &lt;td class="confluenceTd"&gt;$group&lt;/td&gt;			&lt;/tr&gt;		#end	#end		&lt;/table&gt;#end
```


author: Adam Barylak
body: I know this is old, but i found a more streamlined approach to this which will only return the non-personal spaces and only list the administrators in a table. Also the solution provided by the KB article causes massive performance issues even on small to medium sized confluence instances. My solution runs in seconds compared to 30 minutes for the KB solution.

Here is my user macro:

```
## Macro title: Space Administrators
## Macro has a body: N
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: Andrew Frayling
## Modified by: Adam Barylak
## Date created: 21/03/2012
## Date modified: 7/23/2017
## Installed by: <your name>
## Macro to display a list of space administrators
## @noparams
#set($containerManagerClass = $content.class.forName('com.atlassian.spring.container.ContainerManager'))
#set($getInstanceMethod = $containerManagerClass.getDeclaredMethod('getInstance',null))
#set($containerManager = $getInstanceMethod.invoke(null,null))
#set($containerContext = $containerManager.containerContext)
#set($spaces = $spaceManager.getAllSpaces())
<table class="aui aui-table-interactive">
 <tr>
 <th class="confluenceTh">Space</th><th class="confluenceTh">Administrator(s)</th>
 </tr>
#foreach($spacer in $spaces)
 #if (!$spacer.isPersonal())
 <tr>
 <td class="confluenceTd"><a href="$req.contextPath/display/$spacer.key">$spacer.name</a></td><td class="confluenceTd"><ul>
 #set($administrators = $spaceManager.getSpaceAdmins($spacer))
 #foreach($admin in $administrators)
 <li>#usernameLink($admin.name)</li>
 #end
 </ul>
 </td>
 </tr>
 #end
#end
</table>
```


author: Amalia
body: Another way is to do this: [https://answers.atlassian.com/questions/71742/how-can-i-get-the-browse-space-directory-output-to-include-the-space-administrator](/questions/71742/how-can-i-get-the-browse-space-directory-output-to-include-the-space-administrator)