You dont have javascript enabled! Please enable it!

How to Connect to Azure AD PowerShell In 6 Easy Steps (The Beginner’s Guide)

6 Min. Read

This guide will show you the most straightforward way to connect to Azure AD using PowerShell.

Azure Active Directory, or simply Azure AD, is an enterprise access management and identity system in Microsoft Azure. This system gives you access to rights to your application and manages user identities. As for PowerShell, it enables you to automate tasks, filter, and query data, generate reports, access features that aren’t offered in the UI, and more.

In this comprehensive guide, you’ll learn how to connect to Azure AD PowerShell in only six simple steps. We’ll also cover the new Azure AD changes to current features and its deprecation plan.

That being said, let’s get right into it!

Step 1: Create An Azure Account

This one is pretty obvious, but we had to mention it since this is a beginner-friendly guide!

Setting up an Azure account is actually super easy—all you need is to follow these simple:

Create An Azure Account
Create An Azure Account

1) Head over to www.azure.com

2) Click on Try Azure for free. With an Azure free account, you can explore free amounts of 55+ always free services, and popular services are free for your first 12 months. See the free services on Microsoft Azure.

3) Click on the next Start free button.

4) You’ll be prompted to log in if you already have an account with Microsoft. Some of your details may already be there when you log in.

5) Follow the prompts to verify your account.

6) Give a valid credit card (prepaid credit cards are not acceptable). Don’t worry, setting up a trial account is completely free—seeing your card is just important for Microsoft to verify your identity. However, there will be a record of a $0 transaction on your bank statement.

7) Select Agree.

8) Click on Sign Up. Your account will be ready within a few seconds.

This step is the most important one since you must have an Azure account and be logged in to connect to Azure AD PowerShell.

Related: Update Azure Backup Policy at Scale using PowerShell

Step 2: Install Microsoft Online PowerShell Module

To connect to Azure AD Powershell, you must first install the Microsoft Online PowerShell module. Here’s how to do it in 5 simple steps:

1) Open an elevated Windows PowerShell command prompt (run Windows PowerShell as an administrator).

2) Run the Install-Module MSOnline command.

Install-Module MSOnline

3) If you’re prompted to install the NuGet provider, type Y, and press Enter.

4) If you’re prompted to install the module from PSGallery, type Y and press Enter.

If you’re NOT running Windows 10 or Windows 11, then you can install the 32-bit version of the Microsoft Online Services Sign-in Assistant: Download Microsoft Online Services Sign-in Assistant for IT Professionals (msoidcli_32bit.msi file).

Once the PowerShell module is installed, you can proceed to the next step…

Step 3: Get An Azure Active Directory (Azure AD) Tenant

You need an Azure Active Directory tenant to connect to Azure AD Powershell.

If you have Office 365, Azure, Microsoft 365, Dynamics 365, Power Platform, or Intune, then you already have Azure AD as part of your Microsoft Cloud service. All that’s left is to enable it.

You can sign up for a free Azure trial if you do not have a Microsoft Cloud service. Then sign into the Microsoft Entra portal with your new Azure account.

Select go to Azure Active Directory. On the overview page, select Manage tenants and then select Create.

On the Basics tab, select the type of tenant you want to create, either Azure Active Directory or Azure Active Directory (B2C) as shown in the figure below.

Create a new Azure Active Directory Tenant - Basics
Create a new Azure Active Directory Tenant – Basics

Select Next: Configuration to move on to the Configuration tab. On the Configuration tab, enter the Organization name, the Initial domain name, and the Country/Region as shown in the figure below.

Create a new Azure Active Directory Tenant - Configuration
Create a new Azure Active Directory Tenant – Configuration

Finally, select Next: Review + Create. Review the information you entered and if the information is correct, select Create.

Your new tenant is created with the initial domain that you specified: exampledomain.onmicrosoft.com.

See Also: Verify Azure Hybrid Benefits for Windows and Linux with PowerShell

Step 4: Install the Azure AD PowerShell

Installing the Microsoft Azure Active Directory module is essential to access Azure AD PowerShell.

This module is important since it enables you to perform many Office 365 user and organization administration tasks through PowerShell. It’s also effective for bulk tasks like password policies, password resets, license management, license reporting, and more.

Install the Azure AD PowerShell Module
Install the Azure AD PowerShell Module

However, it’s worth mentioning that this module doesn’t allow you to manage the features of Exchange Online, SharePoint/OneDrive, Microsoft Teams, or Skype for Business. These require a separate PowerShell module and PowerShell connection method.

You can use “Get-Module AzureAD -ListAvailable” to check if the Azure AD PowerShell is already installed.

Get-Module AzureAD -ListAvailable

Use the following cmdlet to view any installed module on your machine:

Get-InstalledModule

Finally, type “$PSVersionTable.PSVersion” to check the current version of PowerShell.

$PSVersionTable.PSVersion

Here’s how to install the AzureAD PowerShell:

1) Click Start, type PowerShell

2) Select Windows PowerShell

3) Right-Click and select Run as administrator

4) Type “Install-Module AzureAD” then press Enter.

Install-Module AzureAD

5) Type “A” and press Enter to confirm that you are sure you want to install the modules from ‘PSGallery’.

Related: Create Azure Backup Protection Policy with PowerShell

Step 5: Connect to Azure AD

Connecting to Azure AD can be done through the following cmdlet: “Connect-AzureAD

Connect-AzureAD

When prompted, enter your credentials (i.e., username & password) for your Azure account and approve the Azure AD Multi-Factor Authentication prompt.

The credentials should be entered in the format <username>@<tenantdomain>, where <tenantdomain> is replaced with your actual tenant domain.

Step 6: Use Azure AD Cmdlets

You can now run various cmdlets to manage Azure AD objects and perform other tasks.

Use Azure AD Cmdlets
Use Azure AD Cmdlets

You can run the “Get-Command -Module AzureAD“, to see the Azure AD module cmdlets, which gives you a list of different PowerShell cmdlets that you can use.

Get-Command -Module AzureAD

You can also start using the cmdlets in your PowerShell script, like “Disconnect-AzureAD” to disconnect from Azure in your PowerShell session.

Disconnect-AzureAD

With the Azure AD PowerShell, you’ll be able to manage applications, groups, and users on Azure and Office 365 with activities like generating reports, exporting data, automating tasks, performing operations in bulk, and more.

Note: You can install the Azure AD PowerShell on server or client operating systems.

See Also: How to create bulk users in Azure AD using PowerShell

Important: The Azure AD PowerShell is Planned for Deprecation

As part of bi-annual communication trains that will take place every September and March, Microsoft Azure is announcing feature deprecations and product retirement communications.

This model will make adopting new, more secure technologies easier since you’ll have predictable feature and product changes.

Microsoft strongly recommends trying the Microsoft Graph PowerShell SDK if you access Azure AD through the Azure AD PowerShell or MSOnline PowerShell module, which enables you to access all MS Graph APIs and supports PowerShell 7, external identities, and modern authentication.

Install-Module -Name Microsoft.Graph

But more importantly, Microsoft Graph PowerShell enables you to interact with Azure AD the same way you do with the old Azure AD PowerShell.

Remember that any script written in Azure AD PowerShell Microsoft Graph PowerShell will not work with Microsoft Graph by default. The names of the new cmdlets are easy to use; you can simply use Mg instead of AzureADMS or AzureAD.

This is quite good news, but becoming familiar with the new cmdlets is only half the battle—there are still renamed parameters, modules, and more that you’ll need to be familiar with.

According to Microsoft, you’ll need to document your scripts based on defined criteria and upgrade them to migrate. Then you’ll need to uninstall AzureAD PowerShell and install the Microsoft Graph PowerShell SDK. Finally, you’ll need to find equivalents to the Microsoft Graph PowerShell cmdlet.

Note: The deprecation of both PowerShell modules MSOL and AAD is planned after December 2022.

Learn how to upgrade from Azure AD PowerShell to Microsoft Graph PowerShell.

Conclusion

That was everything you need to know about connecting to Azure AD using PowerShell.

Now go ahead and follow these steps to a tee and enjoy all the wonderful features of running Azure AD using PowerShell!

FAQs

How can I connect to Microsoft Teams using PowerShell?

Follow these two simple steps to connect to a Microsoft team with Powershell:

Use “Install-Module MicrosoftTeams” to install Microsoft Teams PowerShell Module.

Install-Module MicrosoftTeams

Use the PowerShell cmdlet “Connect-MicrosoftTeams” to connect to Microsoft Teams.

Connect-MicrosoftTeams

How can I connect to Exchange Online using PowerShell?

Follow these steps to connect to exchange online with Powershell:

Use “Install-Module ExchangeOnlineManagement” to install the PowerShell Module for Exchange Online Management.

Install-Module ExchangeOnlineManagement

Use the “Connect-ExchangeOnline” cmdlet to connect to Exchange Online.

Connect-ExchangeOnline

How can I connect to SharePoint Online using PowerShell?

Follow these steps to connect to Sharepoint Online using PowerShell:

Install the SharePoint Online Management Shell by downloading and running the SharePoint Online Management Shell or installing the module from the PowerShell Gallery:

Install-Module -Name Microsoft.Online.SharePoint.PowerShell

Once installed, the module is available for use, and you do not need to install it again until you need features introduced in a later version.

Use the “Connect-SPOService” cmdlet to connect to SharePoint Online.

Connect-SPOService

__
Thank you for reading my blog.

If you have any questions or feedback, please leave a comment.

-Charbel Nemnom-

Photo of author
About the Author
Charbel Nemnom
Charbel Nemnom is a Senior Cloud Architect, Swiss Certified ICT Security Expert, Certified Cloud Security Professional (CCSP), Certified Information Security Manager (CISM), Microsoft Most Valuable Professional (MVP), and Microsoft Certified Trainer (MCT). He has over 20 years of broad IT experience serving on and guiding technical teams to optimize the performance of mission-critical enterprise systems with extensive practical knowledge of complex systems build, network design, business continuity, and cloud security.

Related Posts

Previous

Vembu BDRSuite v5.5.0 is GA! All You Should Know #Vembu #BCDR

Update Rollup 1 for System Center 2022 is Now Available

Next

Let me know what you think, or ask a question...

error: Alert: The content of this website is copyrighted from being plagiarized! You can copy from the 'Code Blocks' in 'Black' by selecting the Code. Thank You!