connect-azaccount

In this Azure PowerShell article, we will discuss the syntax and usage of the connect-azaccount PowerShell command with some examples of how to use this command.

connect-azaccount

The connect-azaccount is a very good PowerShell command that can help you connect to Azure with one particular authenticated account so that you can use the Azure PowerShell commands.

Syntax of connect-azaccount

Below is the syntax of the connect-azaccount PowerShell command.

connect-azaccount
Connect-AzAccount
 -Credential <PSCredential>
 -Tenant <String>
Connect-AzAccount

 -Tenant <String>  [-Subscription <String>]

Let’s discuss a few examples of how to use the Connect-AzAccount PowerShell command.

Example-1

You can run the below Azure PowerShell command to connect to Azure with an Azure account.

Connect-AzAccount 

After executing the PowerShell command, you must provide the Microsoft account or organizational ID credentials as shown below.

connect-azaccount -identity -accountid

Once signed in successfully, I got the expected output, as shown below.

PS C:\WINDOWS\system32> Connect-AzAccount

Account                   SubscriptionName         TenantId                             Environment
-------                   ----------------         --------                             -----------
fewlines4biju@hotmail.com Visual Studio Enterprise 5d9d690a-0310-474d-ae8b-42df2d549228 AzureCloud 

See the same output below

Connect-AzAccount

Example-2

You can execute the below Azure PowerShell command to connect to Azure with Managed Service Identity.

Connect-AzAccount -Identity
Set-AzContext -Subscription "Visual Studio Enterprise"

After executing the above PowerShell command, I got the output as expected. You can check out the screenshot below.

connect-azaccount -identity

Example-3

You can also use the tenant and SubscriptionId with the Connect-AzAccount PowerShell command.

Connect-AzAccount -Tenant '5d9d690a-0310-474d-ae8b-42df2d549228' -SubscriptionId '1cdf4300-dee5-4518-9c9c-feaa72a5cbd1'

After executing the above PowerShell command, I got the expected output

connect-azaccount -serviceprincipal

Once you are done, you can use the Disconnect-AzAccount PowerShell command to disconnect from the Azure account that you are connected to.

You may also like following the articles below

Final Thoughts

In this Azure PowerShell article, we discussed the syntax and usage of the connect-azaccount PowerShell command with examples of how to use this command. Thanks for reading this article !!!