Automate Confluence Integration Tasks from PowerShell
The CData ADO.NET Provider for Confluence is a standard ADO.NET Provider that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time access to Confluence.
ADO.NET Provider
The ADO.NET Provider provides a SQL interface for Confluence; this tutorial shows how to use the Provider to retrieve Confluence data.
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.
-
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 }