How to list Tenants and Tag Sets

I’m using Octopus 2018.8.8. How can I get a list of Tenant Names along with the Tenant Tags assigned?

I’ve been using PowerShell and the API and I’ve been able to get a list of Tenants, and separately a list of Tenant Tags belonging to a particular TagSet. But cannot figure out how to get them together.

My TagSet is called Integrations and looks something lie:

Tenant1 might have Integration/Tag2
Tenant2 might have Integration/Tag1 and Integration/Tag3

So what I’m after is a list of Tenants and which Integration tags they have.

Any advice appreciated.


Hi Jamie,

Thanks for getting in touch! I may be oversimplifying your requirements here but I have created a simple API script using the Octopus.Client to get all Tenants and return their name, followed by their Tag Set / Tag.

For example, I have two Tenants (Tenant-A & Tenant-B) and two Tag Sets each with two tags (TagSet-A/Tag-1, etc). My script returns the following.


This script uses the Octopus.Client to get the Tenant’s on my instance and simply write out the name of each one and their connected Tag Set / Tags in a foreach loop.

Add-Type -Path 'C:\MyScripts\Octopus.Client.dll'
# Make sure you have a recent version! Here is how to check...

# Create endpoint and client.
# This uses the above Octopus.Client.dll to create an authenticated endpoint at your Octopus server and a client variable containing the API resources you will call on.
$endpoint = New-Object Octopus.Client.OctopusServerEndpoint("http://YourOctopusServer/", "API-KEY")
$client = New-Object Octopus.Client.OctopusClient($endpoint)

# Get all Tenants on server and add to $tenants variable
$tenants = $client.Repository.Tenants.FindAll()

# Foreach tenant in the variable, write the name then associated tag sets/tags. 
foreach ($tenant in $tenants){

If this is not quite what you were after, let me know and I’ll help out however I can.

Best regards,

Hi Jamie,

Sorry I overlooked the part where you only wanted to return a specific Tag Set.

I have added a Where-Object to my loop to only return the Tag Set that matches the string you want to look for.

foreach ($tenant in $tenants | Where-Object {$_.TenantTags -match "TagSet-A"}){

Best regards,


Thanks for the feedback.

After plugging in my server and API key the script fails on

$tenants = $client.Repository.Tenants.FindAll()

error is:
You cannot call a method on a null-valued expression.
At line:23 char:1

  • $tenants = $client.Repository.Tenants.FindAll()
  •   + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : InvokeMethodOnNull

This is an older version of Octopus (2018.8.8 and Octopus.client.dll 4.47.0 because later versions require Spaces which we do not have access to with our version.) Any suggestions?

Hi Jamie,

Thanks for getting back. I downloaded 2018.8.8 onto my VM and did some testing. It looks like the method I’m using to create the $client variable didn’t exist for this version of Octopus.client.

Specifically, creating a new object of Octopus.Client.OctopusClient

If you create a new Octopus.Client.OctopusRepository object then things should work. You will also need to edit the line where we FindAll tenants to reflect this change.

So changing our $client and $tenant variables, they should now look like this.

$client = New-Object Octopus.Client.OctopusRepository($endpoint)
$tenants = $client.Tenants.FindAll()

Let me know if this works.

Best regards,


That got me to what I needed. :ok_hand:

I understand that supporting older versions of software can be a pain and I appreciate you taking the time to help me out with this.



Hi Jamie,

Thanks for the update! We’re always happy to help out wherever we can. :slight_smile:

Feel free to get in touch at any time if you have any questions or thoughts at all.

Best regards,

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.