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

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,211 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,355 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. MughundhanRaveendran-MSFT 12,411 Reputation points

    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,336 Reputation points

    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.



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

    0 comments No comments