Retrieve Azure Tenant Id using PowerShell

Reading Time: 1 minute

CodeSnippets #1

I have an idea to do a series of short blog posts over the year with helpful PowerShell functions, SQL code or problems I’ve encountered. The kind of thing I wouldn’t bother writing about as it would barely hit 200 words. I’d love some feedback on whether these “snippets” are helpful.


This is a very handy little function that I refer to on a regular basis when working with Azure and Power BI in PowerShell. The purpose of the function is to quickly retrieve the tenant Id of any Azure tenant based on the provided parameter. The user can provide a domain name or a valid email address. The function queries Azure anonymously so there’s no requirement to login first.

You can also find this up on my Github. PRs are always welcome!

Enjoy!

 

You may also like...

3 Responses

  1. Dana Epp says:

    OK, so what happens when you use an email address from gmail or outlook? I have dana@outlook.com. But getting the Azure tenant ID for outlook.onmicrosoft.com is NOT the same as mine, which is danaoutlook.onmicrosoft.com.

    • Craig says:

      Hey Dana, So I had an extra chunk of code to handle that situation but I can’t locate it just now. I’ll try to dig this out but it is possible with the function. Until then, you can pull the function apart and pass your email through as the onmicrosoft.com address and it should return the correct tenantID. Let me know how you get on. Ta, Craig

Leave a Reply