Locating tenant that a subscription belongs to, from subscription id

Aaron 41 Reputation points
2023-01-10T04:18:14.597+00:00

We're getting azure subscription payment overdue messages for a subscription that we can't find - is there any easy way to work out the tenant id/name from a given subscription id?

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,665 questions
0 comments No comments
{count} vote

Accepted answer
  1. Bas Pruijn 951 Reputation points
    2023-01-10T16:54:39.323+00:00

    Sure there is. Using this Powershell function you can find the tenantID of a subscriptionID:

    function get-tenantIdFromSubscriptionID($subId){
        $response = try {(Invoke-WebRequest -UseBasicParsing -Uri "https://management.azure.com/subscriptions/$($subId)?api-version=2015-01-01" -ErrorAction Stop).BaseResponse} catch { $_.Exception.Response } 
        $stringHeader = $response.Headers.ToString()
        return($stringHeader.SubString($stringHeader.IndexOf("login.windows.net")+18,36))
    }
    
    get-tenantIdFromSubscriptionID("<subscriptionID>")
    

    Then you can go to https://portal.azure.com/*<tenantID*> to try to log into the specific tenant.

    To honor the source of this very helpful function: https://www.lieben.nu/liebensraum/2020/08/get-tenant-id-using-azure-subscription-id/

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. darsha-MSFT 101 Reputation points Microsoft Employee
    2023-01-10T06:17:48.117+00:00

    Hello @Aaron ,

    In order to check the subscription's tenant, you need to have RBAC access to the subscription.

    If you have access to the subscription then you can call this REST API and get the subscription's associated tenant ID https://learn.microsoft.com/en-us/rest/api/resources/subscriptions/get?tabs=HTTP.

    If you do not have access to the subscription and unsure under which tenant the subscription is residing, then I would suggest to open a Support ticket with Azure Subscription Management Team:

    277708-image.png

    Also, raising a support ticket to Azure Billing and Subscription management team is free of cost.

    I hope this helps.

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.

    1 person found this answer helpful.
    0 comments No comments