Share via

How to connect Azure by using the PowerShell cmdlet Connect-AzAccount

SieraLight 96 Reputation points
Nov 23, 2020, 3:41 PM

I'm trying to apply VPN Gateway lesson on Azure Learn However I faced many issue to complete the following steps in many lessons, there are no clear lesson to follow or even steps

Azure by using the PowerShell cmdlet Connect-AzAccount

Could you help me by How to with an easy step by step methods? YouTube video will be much better to follow then?

Thanks

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,358 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Andreas Baumgarten 119.5K Reputation points MVP
    Nov 23, 2020, 3:55 PM

    The Connect-AzAccount is required in PowerShell to connect and authenticate the PowerShell session with Azure.

    After the Azure connection is successfully done you can use other Az cmdlets in the PowerShell script.

    These are the basics to start with Connect-AzAccount:

    # Get the credentials for Azure login  
    $Cred = Get-Credential  
    # Connect to Azure with the credentials   
    Connect-AzAccount -Credential $Cred  
    

    More details about Connect-AzAccount you will find here: https://learn.microsoft.com/en-us/powershell/module/az.accounts/connect-azaccount?view=azps-5.1.0

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    1 person found this answer helpful.
    0 comments No comments

  2. R, Naveen 41 Reputation points
    Sep 9, 2021, 9:48 AM

    Hi folks,

    @Anonymous Thanks for this article.

    I am trying to connect to Azure using Thumbprint, but the Subscription Name is showing empty.

    Account SubscriptionName TenantId Environment
    ------- ---------------- -------- -----------
    xxx-xx-x-x-xx xxx-xx-xxx-x-xx AzureCloud

    Any reasons why and please let me know how to fix this?

    Thanks,
    Naveen

    0 comments No comments

  3. Suryawanshi, Rakesh 1 Reputation point
    Mar 11, 2021, 11:44 AM

    NAME
    Connect-AzAccount

    SYNOPSIS
    Connect to Azure with an authenticated account for use with cmdlets from the Az PowerShell modules.

    ------------ Example 1: Connect to an Azure account ------------
    
    Connect-AzAccount
    
    Account                SubscriptionName TenantId                Environment
    -------                ---------------- --------                -----------
    ******@contoso.com  Subscription1    xxxx-xxxx-xxxx-xxxx     AzureCloud
    
    
    
    
    Example 2: (Windows PowerShell 5.1 only) Connect to Azure using organizational ID credentials
    
    $Credential = Get-Credential
    Connect-AzAccount -Credential $Credential
    
    Account                SubscriptionName TenantId                Environment
    -------                ---------------- --------                -----------
    ******@contoso.com  Subscription1    xxxx-xxxx-xxxx-xxxx     AzureCloud
    
    
    
    
    Example 3: Connect to Azure using a service principal account
    
    $Credential = Get-Credential
    Connect-AzAccount -Credential $Credential -Tenant 'xxxx-xxxx-xxxx-xxxx' -ServicePrincipal
    
    Account                SubscriptionName TenantId                Environment
    -------                ---------------- --------                -----------
    xxxx-xxxx-xxxx-xxxx    Subscription1    xxxx-xxxx-xxxx-xxxx     AzureCloud
    
    
    
    
    Example 4: Use an interactive login to connect to a specific tenant and subscription
    
    Connect-AzAccount -Tenant 'xxxx-xxxx-xxxx-xxxx' -SubscriptionId 'yyyy-yyyy-yyyy-yyyy'
    
    Account                SubscriptionName TenantId                Environment
    -------                ---------------- --------                -----------
    ******@contoso.com  Subscription1    xxxx-xxxx-xxxx-xxxx     AzureCloud
    
    
    
    
    ----- Example 5: Connect using a Managed Service Identity -----
    
    Connect-AzAccount -Identity
    
    Account                SubscriptionName TenantId                Environment
    -------                ---------------- --------                -----------
    MSI@50342              Subscription1    xxxx-xxxx-xxxx-xxxx     AzureCloud
    
    
    
    
    Example 6: Connect using Managed Service Identity login and ClientId
    
    $identity = Get-AzUserAssignedIdentity -ResourceGroupName 'myResourceGroup' -Name 'myUserAssignedIdentity'
    Get-AzVM -ResourceGroupName contoso -Name testvm | Update-AzVM -IdentityType UserAssigned -IdentityId $identity.Id
    Connect-AzAccount -Identity -AccountId $identity.ClientId # Run on the virtual machine
    
    Account                SubscriptionName TenantId                Environment
    -------                ---------------- --------                -----------
    yyyy-yyyy-yyyy-yyyy    Subscription1    xxxx-xxxx-xxxx-xxxx     AzureCloud
    
    
    
    
    ------------ Example 7: Connect using certificates ------------
    
    $Thumbprint = '0SZTNJ34TCCMUJ5MJZGR8XQD3S0RVHJBA33Z8ZXV'
    $TenantId = '4cd76576-b611-43d0-8f2b-adcb139531bf'
    $ApplicationId = '3794a65a-e4e4-493d-ac1d-f04308d712dd'
    Connect-AzAccount -CertificateThumbprint $Thumbprint -ApplicationId $ApplicationId -Tenant $TenantId -ServicePrincipal
    
    Account             SubscriptionName TenantId            Environment
    -------             ---------------- --------            -----------
    xxxx-xxxx-xxxx-xxxx Subscription1    xxxx-xxxx-xxxx-xxxx AzureCloud
    
    Account          : 3794a65a-e4e4-493d-ac1d-f04308d712dd
    SubscriptionName : MyTestSubscription
    SubscriptionId   : 85f0f653-1f86-4d2c-a9f1-042efc00085c
    TenantId         : 4cd76576-b611-43d0-8f2b-adcb139531bf
    Environment      : AzureCloud
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.