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.
Table of Contents
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-azaccountConnect-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.

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

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.

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

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 !!!

I am Rajkishore, and I am a Microsoft Certified IT Consultant. I have over 14 years of experience in Microsoft Azure and AWS, with good experience in Azure Functions, Storage, Virtual Machines, Logic Apps, PowerShell Commands, CLI Commands, Machine Learning, AI, Azure Cognitive Services, DevOps, etc. Not only that, I do have good real-time experience in designing and developing cloud-native data integrations on Azure or AWS, etc. I hope you will learn from these practical Azure tutorials. Read more.
