How to Get Tenant Name in Power Automate

When I was working on a Power Apps and Power Automate solution to create SharePoint sites automatically, I needed it to work across any tenant.

The flow creates SharePoint sites via REST API calls, so we must pass the tenant name.

However, Power Automate does not provide any direct action or function to get the tenant name.

If we hardcode the tenant name, the flow will fail when the solution is imported into another tenant. That means the solution is not reusable.

To solve this problem, I used an environment variable inside a solution. When someone imports the solution, they only need to provide a SharePoint site address. From this site address, we can dynamically extract the tenant name in Power Automate and use it in REST API calls.

In this tutorial, I will show you how to get the tenant name in Power Automate using two different ways:

  • Get Tenant name from an Environment variable
  • Get Tenant name from a SharePoint Action input

Get Tenant Name in Power Automate

In this section, I will first show how to get the tenant name from an environment variable inside a solution. After that, I will explain how to get the tenant name from a SharePoint action input in Power Automate.

Get the Tenant Name From an Environment Variable Inside a Solution

For this example, I created a Power Apps Solution with an Environment variable named Site Address.

How to get the Tenant name in Power Apps canvas apps

Now we create the flow inside the solution, then get the tenant name.

To do this, follow the steps below:

  1. In the Power Apps Solution, click + New -> Automation -> Cloud flow -> Instant.
get solution data to power automate
  1. Enter a name for the flow, select the Manually trigger a flow trigger, and then click Create.
How to find your Microsoft 365 tenant name in Power Automate
  1. Then add a compose action and provide the Environment Variable from the dynamic content.
HOW TO FIND TENANT name-POWER AUTOMATE

Now save the flow and run it manually; you can then see the Site Address in the compose action output.

Get the Tenant Name From an Environment Variable Inside a Solution
  1. Now, to extract the tenant name, add another Compose action and enter the expression below:
first(split(replace(outputs('Compose'),'https://',''),'.sharepoint.com'))
Get the Tenant Name From an Environment Variable Inside a Solution in Power Automate

Save the flow and run it. You will see the tenant name in the Compose action output.

How to Get Tenant Name in Power Automate

This way, you can get the tenant name from an environment variable inside a solution. You can also use this value in Power Apps if required.

Get the Tenant Name from a SharePoint Action Input in Power Automate

In this example, I created an instant cloud flow and used a Get items action for a SharePoint list.

Power Automate Get the Tenant Name from a SharePoint Action Input

Now, I want to get the tenant name, and I will show you how to do it.

To do this, follow the steps below:

Add a compose action and provide the following expression:

actions('Get_items').inputs.parameters.dataset

Where:

  • actions(‘Get_items’): Refers to the Get items action in your flow (The name must exactly match the action’s internal name (from Peek code)).
  • .inputs: Returns everything you passed into the Get items action.
  • .parameters: Inside the inputs, Power Automate stores connector-specific values under parameters.
  • .dataset: It returns the SharePoint Site URL used by Get items.
Get the Tenant Name from a SharePoint Action Input in Power Automate

Now save the flow and run it manually, then you can see the Site Address in the compose action output.

How to find tenant name in SharePoint using Power Automate

Now, to extract the tenant name, add another Compose action and enter the expression below:

first(split(replace(outputs('Compose_1'),'https://',''),'.sharepoint.com'))
How to get tenant name in power automate flow

Save the flow and run it. You will see the tenant name in the Compose action output.

How to Get the Tenant Name from a SharePoint Action Input in Power Automate

Conclusion

In this tutorial, I explained two different ways to get the tenant name in Power Automate. First, we learned how to retrieve the tenant name from an environment variable within a solution, which makes the solution reusable across different tenants. Next, we saw how to get the tenant name from a SharePoint action input by reading the site address used in the action.

You may also like:

Power Apps functions free pdf

30 Power Apps Functions

This free guide walks you through the 30 most-used Power Apps functions with real business examples, exact syntax, and results you can see.

Download User registration canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App