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.
Get-AzTenant
will help.
Get-AzTenant
[[-TenantId] <String>]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Make sure the version of Az is 4.5.0(the latest version).
You could Install-Module -Name Az
to update it.
Have you tried the command Get-AzureADTenantDetail
Get-AzureADTenantDetail
[-All <Boolean>]
[-Top <Int32>]
[<CommonParameters>]
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
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