How can I get the Azure Directory(Tenant) name in which I have logged in by PowerShell ?
I have tried 'Get-AzContext', but it only provides the Tenant ID. Tenant name or default domain name is not included in the output.
How can I get the Azure Directory(Tenant) name in which I have logged in by PowerShell ?
I have tried 'Get-AzContext', but it only provides the Tenant ID. Tenant name or default domain name is not included in the output.
On
Have you tried the command Get-AzureADTenantDetail
Get-AzureADTenantDetail
[-All <Boolean>]
[-Top <Int32>]
[<CommonParameters>]
On
You need the AzureAD module for PowerShell and you will get the information by Connecting and then running the Get-AzureADTenantDetail
Install-Module AzureAD
Connect-AzureAD
Get-AzureADTenantDetail
On
To get the tenant name for the tenant that you have logged in using the Powershell Az module:
$azTenantId = (Get-AzContext).Tenant.Id
$azTenantName = (Get-AzTenant | where-object Id -eq $azTenantId).Name
To get the default tenant domain for the tenant that you have logged in:
$azTenantDomain = Invoke-AzRestMethod `
-Method get `
-Uri https://graph.microsoft.com/v1.0/domains `
| Select-Object -ExpandProperty Content `
| Convertfrom-json `
| Select-Object -ExpandProperty value `
| where-object -Property isDefault -eq $true `
| Select-Object -ExpandProperty id
On
I've just run into this - the problem may also be (and was for me) if you're signed in with a service principal with certificate it doesn't have the tenant information in Get-AzTenant (because the REST API itself doesn't provide the information to service principals).
Like mpowrie said you need to switch to Graph API.
Get-AzTenantwill help.Make sure the version of Az is 4.5.0(the latest version). You could
Install-Module -Name Azto update it.