1
votes

When I type this command "Add-AzureAccount" on Azure PowerShell, it returns all the tenants associated with the account. How to know which tenant belongs to the Active Directory that I have created in the same subscription using PowerShell. Lets say that the default domain created in the AD is abc.onmicrosoft.com. Using this msolDomainName, can i get the tenantid it is associated with?

Kindly suggest.

2

2 Answers

2
votes

well, this was helpful:

param([string]$TenantName = (Read-Host "What is your tenant name? (abc.onmicrosoft.com)"))

[xml]$data = (New-Object System.Net.WebClient).DownloadString("https://login.windows.net/$TenantName/FederationMetadata/2007-06/FederationMetadata.xml")

$dirtyID = $data.EntityDescriptor.entityID.Replace("https://sts.windows.net/", "")

$dirtyID.Replace("/", "")

1
votes

Hope this command will help you

PS C:\>(Get-AzureAccount).ActiveDirectories.ActiveDirectoryTenantID

for detailed please use given link

http://www.virtualizationadmin.com/articles-tutorials/cloud-computing/microsoft/managing-your-microsoft-azure-active-directory-instance.html