Script for getting list of tenants by version

Hello again fellow Octopi,

I have been trying to figure out a good way to gather a list of tenants by version number. This would be SUPER helpful because when I rollout new releases to production I sometimes miss updating a few tenants. Right now, we have close to 1000 tenants and I was told to sort them in the gui and manually look through each of them however this create a large margin of error and also takes a long time. I have been trying to teach myself PowerShell since it has been AMAZING to use scripts but I am a slow learner. I have also tried working with the OD cli however I am having trouble. Is it even possible to use a script to get a list of tenants sorted by version number?

Please let me know your thoughts! :smiley: I really appreciate you guys!

Hi @bross,

Thanks for getting in touch! I whipped up something simple, though you will need to confirm whether it’s what you’re after. Take note, I’m no PowerShell expert, I’m sure there exists multiple ways to handle this better. :slight_smile:

#Add-Type -Path 'C:\MyScripts\Newtonsoft.Json.dll'
Add-Type -Path 'C:\MyScripts\Octopus.Client.dll' 

# Create endpoint and client
$endpoint = New-Object Octopus.Client.OctopusServerEndpoint("http://YourOctopusServer/", "API-KEY")
$client = New-Object Octopus.Client.OctopusClient($endpoint)

# Get all items from the dashboard if they were a tenanted deployment and succeeded
$items = $client.Repository.Dashboards.GetDashboard().Items | Where-Object { ($_.TenantId -ne $null) -and ($_.State -eq "Success")}

# Get the project name, tenant name, and release version for each item.
foreach ($deploy in $items){
    Write-Host "Project Name: "$client.Repository.Projects.Get($deploy.ProjectId).Name
    Write-Host "Tenant Name: "$client.Repository.Tenants.Get($deploy.TenantId).Name
    Write-Host $deploy.releaseVersion
    }

Octopus stores a lot of handy information on the dashboard, including the latest releases for each environments and information about that release, including the release version. By checking the dashboard for any items which were associated with a Tenanted deployment, and successful, I think we can reliably identify the current release version per project for each Tenant.

Does this look like it will help, or at least help get you started?

Feel free to let me know if you have any issues with this, or if it is not exactly what you’re after.

Hope that helps!

Best regards,
Daniel