Need to create a function in PowerShell which connects to multiple Azure Tenants without copy pasting tenent id manualy , Function should list the tenants

Azure-learning 56 Reputation points
2022-06-29T12:04:08.553+00:00

Need to create a function in PowerShell which connects to multiple Azure Tenants. This Function should give the list of all the azure tenants and there is no need to copy paste tenant ids for connecting to the tenant

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,237 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,359 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. MughundhanRaveendran-MSFT 12,421 Reputation points
    2022-06-30T12:34:49.437+00:00

    Hi @NehaBameta-3476 ,

    Thanks for posting your query in Q&A.

    You can get the list of tenants using the Rest API List method and then invoke the rest api from powershell using the Invoke-RestMethod command. This powershell script should list all tenants. Once the powershell script is working on your local machine, you can deploy the script to the Azure powershell functions. Alternatively, you can directly develop the script in the Azure functions portal.

    Hope this helps! Feel free to reach out to me if you have any queries or concerns.

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.

    0 comments No comments

  2. Limitless Technology 39,351 Reputation points
    2022-07-03T09:19:24.803+00:00

    Hi there,

    I suppose that you cannot achieve your requirement without manually adding the tenant ID in your script.

    You can use Get-AzureRmResource to get the list of resources in an Azure Subscription. By default, this Cmdlet will list all resources in an Azure Subscription. To get a list of certain resource types, you can specify an OData filter query.

    Get-AzureADTenantDetail

    ---------------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept it as an answer–

    0 comments No comments