Export-CTReports.ps1 — Setup Instructions
Automates pulling the latest completed Change Tracker report output(s) to a file share, so tools like Power BI can pick them up on a schedule without manual export.
What it does
Logs into the Hub API and, for each report ID listed, finds the most recently completed run, renders it in your chosen format, and downloads it to a folder or file share. It doesn’t trigger reports to run — it just picks up whatever Change Tracker’s own schedule already produced.
1. Customize before running
Edit the param() block at the top of the script (or pass these as arguments):
| Setting | What to set it to |
|---|---|
$HubUrl |
https://localhost/api if running on the same server as the Hub, otherwise your Hub’s URL + /api |
$OutputPath |
The folder or file share path your downstream tool (e.g. Power BI) reads from |
$ReportItemIds |
One or more report IDs — see below for how to find these |
$Format |
Csv, CsvXlsx, Pdf, Word, or Excel — same options as the report viewer’s Download button. Defaults to Csv. |
If the Hub uses a self-signed/internal cert, uncomment the two $PSDefaultParameterValues["...:SkipCertificateCheck"] lines near the top of the script.
2. Finding your report IDs
Run this once (with your own admin credentials, or after setting the env vars from step 3) to list every scheduled report with its ID:
$HubUrl = "https://localhost/api"
$authBody = @{ UserName = "admin"; Password = "yourpassword"; provider = "credentials" } | ConvertTo-Json
Invoke-RestMethod -Uri "$HubUrl/auth/credentials" -Method Post -Body $authBody `
-SessionVariable Session -ContentType "application/json" | Out-Null
$reports = Invoke-RestMethod -Uri "$HubUrl/reports/scheduled" -Method Get -WebSession $Session
$reports.Items | Select-Object Id, @{N='Name';E={$_.ContainerReport.DisplayName}} | Format-Table -AutoSize
Copy the Id value(s) for whichever reports you want exported into $ReportItemIds in the script.
3. Setting the credential environment variables
Run as the account that will execute the scheduled task (ideally a dedicated low-privilege service account, not a personal admin login):
[Environment]::SetEnvironmentVariable("CT_HUB_USER", "svc-reportexport", "User")
[Environment]::SetEnvironmentVariable("CT_HUB_PASSWORD", "REPLACE_ME", "User")
These only take effect in new sessions started after being set — close and reopen PowerShell before testing.
4. Windows Task Scheduler setup
- Save the script, e.g.
C:\Scripts\Export-CTReports.ps1 - Open Task Scheduler → Create Task
- On the General tab: set it to run whether user is logged on or not, using the service account whose env vars you set in step 3
- On the Triggers tab: add a new trigger for Weekly/Monthly, matching your report cadence, timed a bit after the reports actually finish running in Change Tracker
- On the Actions tab: add a new action
- Program/script:
powershell.exe - Add arguments:
-ExecutionPolicy Bypass -File "C:\Scripts\Export-CTReports.ps1"
- Program/script:
- Save the task, then right-click it and select Run once to confirm it authenticates and drops a file on the share before trusting the schedule
Export-CTReports.ps1 (6.3 KB)