0
votes

In the Azure Active Directory Powershell module (AzureAD) you could use

$conn = Connect-AzureAd

and then get the Azure tenant ID using

$conn.tenantId

Straightforward enough.

With the new Azure Powershell module (Az) you can also capture the connection response

$conn = Connect-AzAccount

But there's no TenantId property. How do you get the TenantId ? Get-AzTenant brings back all potential tenants, and no flag for which one the current Azure connection is pointing to.

1
For what I've found you can use the "onmicrosoft" domain name of the tenant as a replacement for the tenantId in almost all case where you need the tenantIdbluuf

1 Answers

0
votes

The new Azure Powershell has shifted this information from top-level connection info to a more hierarchical representation using custom object types.

The PSAzureProfile type instance returned by Connect-AzAccount has a property called Context which is a PSAzureContext type. This object in turn has a Tenant property which is a PSAzureTenant type.

And there in that object is an Id property which has our currently selected Azure tenant ID for the current session.

Sample code:

$conn = Connect-AzAccount
$tenantId = $conn.Context.Tenant.Id

Hopefully documentation will improve on all of these types and how they're structured.