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.