We are proud to share our inclusion in the 2024 Gartner Magic Quadrant for Data Integration Tools. We believe this recognition reflects the differentiated business outcomes CData delivers to our customers.
Get the Report →Automate Confluence Integration Tasks from PowerShell
Are you in search of a quick and easy way to access Confluence data from PowerShell? This article demonstrates how to utilize the Confluence Cmdlets for tasks like connecting to Confluence data, automating operations, downloading data, and more.
The CData Cmdlets for Confluence are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time access to Confluence.
PowerShell Cmdlets or ADO.NET Provider?
The Cmdlets are not only a PowerShell interface to Confluence, but also an SQL interface; this tutorial shows how to use both to retrieve Confluence data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Confluence. To access Confluence data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Confluence.
Once you have acquired the necessary connection properties, accessing Confluence data in PowerShell can be enabled in three steps.
Obtaining an API Token
An API token is necessary for account authentication. To generate one, login to your Atlassian account and navigate to API tokens > Create API token. The generated token will be displayed.
Connect Using a Confluence Cloud Account
To connect to a Cloud account, provide the following (Note: Password has been deprecated for connecting to a Cloud Account and is now used only to connect to a Server Instance.):
- User: The user which will be used to authenticate with the Confluence server.
- APIToken: The API Token associated with the currently authenticated user.
- Url: The URL associated with your JIRA endpoint. For example, https://yoursitename.atlassian.net.
Connect Using a Confluence Server Instance
To connect to a Server instance, provide the following:
- User: The user which will be used to authenticate with the Confluence instance.
- Password: The password which will be used to authenticate with the Confluence server.
- Url: The URL associated with your JIRA endpoint. For example, https://yoursitename.atlassian.net.
PowerShell
-
Install the module:
Install-Module ConfluenceCmdlets
-
Connect:
$confluence = Connect-Confluence -User "$User" -APIToken "$APIToken" -Url "$Url" -Timezone "$Timezone"
-
Search for and retrieve data:
$id = "10000" $pages = Select-Confluence -Connection $confluence -Table "Pages" -Where "Id = `'$Id`'" $pages
You can also use the Invoke-Confluence cmdlet to execute SQL commands:
$pages = Invoke-Confluence -Connection $confluence -Query 'SELECT * FROM Pages WHERE Id = @Id' -Params @{'@Id'='10000'}
ADO.NET
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Confluence\lib\System.Data.CData.Confluence.dll")
-
Connect to Confluence:
$conn= New-Object System.Data.CData.Confluence.ConfluenceConnection("User=admin;APIToken=myApiToken;Url=https://yoursitename.atlassian.net;Timezone=America/New_York;") $conn.Open()
-
Instantiate the ConfluenceDataAdapter, execute an SQL query, and output the results:
$sql="SELECT Key, Name from Pages" $da= New-Object System.Data.CData.Confluence.ConfluenceDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.key $_.name }