How do you write a power script to show metadata about all the pages in a space?
Asked by Michael Zhao:

Looking for help with writing a macro to audit the pages within a space in a Confluence instance, showing the following fields:

* Page name
* Link to page
* Last updated/modified date
* Original Poster (creator)

Previous implementation was deployed on a created page within the space being audited, and showed a table of all the pages within the space.


Answers:
author: Dave Liao
body: [@Michael Zhao](/t5/user/viewprofilepage/user-id/5115756) - hi Michael!

Are you actually looking for a [Power Scripts for Confluence](https://marketplace.atlassian.com/apps/1219507/power-scripts-for-confluence?tab=overview&hosting=datacenter) script?\*

If no, **or** it's not imperative that we use PS, consider a custom user macro:

1. See this example: <https://community.atlassian.com/t5/Confluence-questions/Macro-that-lists-all-pages-for-the-specified-space-with-their/qaq-p/1452170>
2. ...and consider THIS example if you want to extend the first example: <https://community.atlassian.com/t5/Confluence-articles/A-Child-Page-by-Label-User-Macro/ba-p/1502246>

\* today I learned that PS for Confluence is a thing! Awesome.

comments: author: Michael Zhao
body: Definitely looks like it matches what I'm looking for. Talked to a former colleague who mentioned the previous iteration was built with Power Scripts, but more looking for a starting point to build it out in a different organizational context, so not a requirement.

Thanks again!


author: Dave Liao
body: [@Michael Zhao](/t5/user/viewprofilepage/user-id/5115756) - FYI if you have an existing PS script, you may be able to extend it using these variables: <https://appfire.atlassian.net/wiki/spaces/PSCONF/pages/15306098/Standard+Variables>


author: Tom_Carrott_Adaptavist
body: Hey [@Michael Zhao](/t5/user/viewprofilepage/user-id/5115756)

I'm a PM in Kolekti (Part of the Adaptavist Group) and we currently have a new discovery idea in the works, a Confluence Cloud add-on designed to streamline multi-space metadata and content management for Confluence Cloud users!

The app aims to streamline content management for Confluence Cloud by offering a centralised hub for all your pages. Imagine a "panoramic view" where you can easily:

* **Find any page:** Effortlessly locate specific content across your entire Confluence instance.
* **Manage at a glance:** View key information across multiple spaces like last edited, created date, page owner, labels, status etc.
* **Organise effortlessly:** Move pages between spaces, copy, archive, or delete them in bulk - no technical skills needed!
* **Maintain control:** Edit metadata fields like labels and permissions for multiple pages simultaneously

Your use case sounds very interesting... would you be interested in a conversation?


author: Roma Bubyakin
body: Hi [@Dave Liao](/t5/user/viewprofilepage/user-id/523242)

*In case you are using **Cloud***

It might also be worth to take a look into our (Wombats Corp) app [User Macro for Confluence Cloud](https://marketplace.atlassian.com/apps/1232013/user-macro-for-confluence-cloud?hosting=cloud&tab=overview)

You can create numerous dynamic macros from the admin panel.

For your exact use case template would be the following:  

```
## get pages in the current space
#set($sort = "-modified-date") ## order by modified date DESC
#set($status = "current") ## skip archived, deleted, and drafted
#set($limit = 250) ## increase pages limit to maximum

#set($url = "/wiki/api/v2/spaces/${space.id}/pages?sort=${sort}&status=${status}&limit=${limit}")

#set($response = $ConfluenceManager.get($url))

## Use of Atlassian UI (AUI) sortable table
<table class="aui aui-table-sortable"> 
  <thead>
    <tr>
      <th>Title</th>
      <th>Link to Page</th>
      <th>Last updated</th>
      <th>Original Poster</th>
    </tr>
  </thead> 
  <tbody>

  ## iterate through results of pages
  #foreach($page in $response.results)
    <tr>
      <td>${page.title}</td>
      <td><a href="${baseUrl}${page._links.webui}">${page._links.webui}</a></td>

      ## Convert datetime to date
      ## "2024-02-13T12:12:31.528Z" -> "2024-02-13"
      #set($createdAt = $StringUtils.substringBefore($page.version.createdAt, "T"))
      <td>${createdAt}</td>

      ## Retrieve additional information by accountId
      #set ( $user = $ConfluenceManager.get("/wiki/rest/api/user?accountId=$page.authorId") )
      <td>$user.displayName</td>
    </tr>
  #end
  </tbody>
</table>
```

The result would be like this:  
![Show metadata about all the pages in a space.png](https://community.atlassian.com/t5/image/serverpage/image-id/286872i3FBBE05FB90B39DE/image-size/large?v=v2&px=999 "Show metadata about all the pages in a space.png")

Regards, Roman


Tags: confluence-server

server