This guide explains how to install the Active Directory (AD) module for PowerShell Core 6.0 and Windows PowerShell. For Windows PowerShell, the document describes how to install the AD module for Windows 7, Windows 8, Windows 8.1, Windows 10, Windows Server 2008 R2, Windows Server 2012 R2, and Windows Server 2016. Feb 26, 2016 Today I share a script to automate all of the manual steps involved with setting up the Active Directory PowerShell module on your Windows 10 workstation. Clickety, Click. Scripty, script. I recently reloaded my everyday work laptop. After three years it had in-place upgrades from Windows 8 to Windows 8.1 to Windows 10.
PowerShell command window with a title bar 'Microsoft Azure Active Directory Module for Windows PowerShell' is either deprecated or obsolete. I still use the old Azure AD module for W indows, but yes, it was deprecated.
-->Summary: Connect to your Office 365 organization using Office 365 PowerShell to perform administration tasks from the command line.
Office 365 PowerShell lets you manage your Office 365 settings from the command line. Connecting to Office 365 PowerShell is a simple process where you install the required software and then connect to your Office 365 organization.
There are two versions of the PowerShell module that you use to connect to Office 365 and administer user accounts, groups, and licenses:
- Azure Active Directory PowerShell for Graph (cmdlets include AzureAD in their name)
- Microsoft Azure Active Directory Module for Windows PowerShell (cmdlets include MSol in their name)
As of the date of this article, the Azure Active Directory PowerShell for Graph module does not completely replace the functionality in the cmdlets of Microsoft Azure Active Directory Module for Windows PowerShell module for user, group, and license administration. In many cases, you need to use both versions. You can safely install both versions on the same computer.
Tip
New to PowerShell? See a video Overview of PowerShell, brought to you by LinkedIn Learning.
What do you need to know before you begin?
Estimated time to complete: 5 minutes
You can use the following versions of Windows:
Windows 10, Windows 8.1, Windows 8, or Windows 7 Service Pack 1 (SP1)
Windows Server 2019, Windows Server 2016, Windows Server 2012 R2, Windows Server 2012, or Windows Server 2008 R2 SP1
Note
Use a 64-bit version of Windows. Support for the 32-bit version the Microsoft Azure Active Directory Module for Windows PowerShell was discontinued in October of 2014.
These procedures are intended for users who are members of an Office 365 admin role. For more information, see About Office 365 admin roles.
Connect with the Azure Active Directory PowerShell for Graph module
Commands in the Azure Active Directory PowerShell for Graph module have AzureAD in their cmdlet name.
For procedures that require the new cmdlets in the Azure Active Directory PowerShell for Graph module, use these steps to install the module and connect to your Office 365 subscription.
Note
See Azure Active Directory PowerShell for Graph module for information about the support for different versions of Microsoft Windows.
Step 1: Install required software
These steps are required once on your computer, not every time you connect. However, you'll likely need to install newer versions of the software periodically.
Open an elevated Windows PowerShell command prompt (run Windows PowerShell as an administrator).
In the Administrator: Windows PowerShell command window, run this command:
If prompted about installing a module from an untrusted repository, type Y and press ENTER.
Step 2: Connect to Azure AD for your Office 365 subscription
To connect to Azure AD for your Office 365 subscription with an account name and password or with multi-factor authentication (MFA), run one of these commands from a Windows PowerShell command prompt (it does not have to be elevated).
Office 365 cloud | Command |
Office 365 Worldwide (+GCC) | Connect-AzureAD |
Office 365 operated by 21 Vianet | Connect-AzureAD -AzureEnvironmentName AzureChinaCloud |
Office 365 Germany | Connect-AzureAD -AzureEnvironmentName AzureGermanyCloud |
Office 365 U.S. Government DoD and Office 365 U.S. Government GCC High | Connect-AzureAD -AzureEnvironmentName AzureUSGovernment |
In the Sign into your account dialog box, type your Office 365 work or school account user name and password, and then click OK.
If you are using MFA, follow the instructions in the additional dialog boxes to provide more authentication information, such as a verification code.
After connecting, you can use the new cmdlets for the Azure Active Directory PowerShell for Graph module.
Connect with the Microsoft Azure Active Directory Module for Windows PowerShell
Commands in the Microsoft Azure Active Directory Module for Windows PowerShell have Msol in their cmdlet name.
Step 1: Install required software
These steps are required once on your computer, not every time you connect. However, you'll likely need to install newer versions of the software periodically.
Install the 64-bit version of the Microsoft Online Services Sign-in Assistant: Microsoft Online Services Sign-in Assistant for IT Professionals RTW.
Install the Microsoft Azure Active Directory Module for Windows PowerShell with these steps:
- Open an elevated Windows PowerShell command prompt (run Windows PowerShell as an administrator).
- Run the Install-Module MSOnline command.
- If prompted to install the NuGet provider, type Y and press ENTER.
- If prompted to install the module from PSGallery, type Y and press ENTER.
Step 2: Connect to Azure AD for your Office 365 subscription
To connect to Azure AD for your Office 365 subscription with an account name and password or with multi-factor authentication (MFA), run one of these commands from a Windows PowerShell command prompt (it does not have to be elevated).
Office 365 cloud | Command |
Office 365 Worldwide (+GCC) | Connect-MsolService |
Office 365 operated by 21 Vianet | Connect-MsolService -AzureEnvironment AzureChinaCloud |
Office 365 Germany | Connect-MsolService -AzureEnvironment AzureGermanyCloud |
Office 365 U.S. Government DoD and Office 365 U.S. Government GCC High | Connect-MsolService -AzureEnvironment USGovernment |
In the Sign into your account dialog box, type your Office 365 work or school account user name and password, and then click OK.
If you are using MFA, follow the instructions in the additional dialog boxes to provide more authentication information, such as a verification code.
How do you know this worked?
If you don't receive any errors, you connected successfully. A quick test is to run an Office 365 cmdlet—for example, Get-MsolUser —and see the results.
If you receive errors, check the following requirements:
A common problem is an incorrect password. Run Step 2 again. and pay close attention to the user name and password you enter.
The Microsoft Azure Active Directory Module for Windows PowerShell requires that the Microsoft .NET Framework 3.5.x feature is enabled on your computer. It's likely that your computer has a newer version installed (for example, 4 or 4.5.x), but backwards compatibility with older versions of the .NET Framework can be enabled or disabled. For more information, see the following topics:
For Windows Server 2012 or Windows Server 2012 R2, see Enable .NET Framework 3.5 by using the Add Roles and Features Wizard
For Windows 7 or Windows Server 2008 R2, see You can't open the Azure Active Directory Module for Windows PowerShell
For Windows 10, Windows 8.1, and Windows 8, see Install the .NET Framework 3.5 on Windows 10, Windows 8.1, and Windows 8
Your version of the Microsoft Azure Active Directory Module for Windows PowerShell might be out of date. To check, run the following command in Office 365 PowerShell or the Microsoft Azure Active Directory Module for Windows PowerShell:
If the version number returned is lower than the value 1.0.8070.2, uninstall the Microsoft Azure Active Directory Module for Windows PowerShell and install the latest version from the link in Step 1.
If you receive a connection error, see this topic:'Connect-MsolService: Exception of type was thrown' error.
See also
This guide explains how to install the Active Directory (AD) module for PowerShell Core 6.0 and Windows PowerShell. For Windows PowerShell, the tutorial describes how to install the AD module for Windows 7, Windows 8, Windows 8.1, Windows 10, Windows Server 2008 R2, Windows Server 2012 R2, and Windows Server 2016.
Michael Pietroforte
Latest posts by Michael Pietroforte (see all)
- Results of the 4sysops member and author competition in 2018 - Tue, Jan 8 2019
- Why Microsoft is using Windows customers as guinea pigs - Reply to Tim Warner - Tue, Dec 18 2018
- PowerShell remoting with SSH public key authentication - Thu, May 3 2018
The installation of the AD module varies significantly for the different Windows and PowerShell versions. At the time of this writing, the AD module that comes with RAST does not work with PowerShell Core 6.0. However, this guide explains how you can manage Active Directory from PowerShell Core even on macOS and Linux.
Windows 7 ^
On a Windows 7 computer, you can follow this procedure to install the Active Directory module:
- Download the Remote Server Administration Tools (RSAT) for Windows 7.
- Open the Control Panel, start typing features, and then click Turn Windows features on or off.
- Scroll down to Remote Server Administration Tools and enable the Active Directory Module for Windows PowerShell in Remote Server Administration Tools > Role Administration Tools > AD DS and AD LDS Tools.
- Run Import-Module ActiveDirectory on a PowerShell console.
Active Directory Module for Windows PowerShell on Windows 7
If the Windows 7 machine only has PowerShell 2.0 installed, you have to add the Import-Module ActiveDirectory command to your profile because PowerShell doesn't load modules automatically. For instance, you can import the module in %UserProfile%My DocumentsWindowsPowerShellprofile.ps1. Makes sure you've set your execution policy to either RemoteSigned or Unrestricted: Set-ExecutionPolicy RemoteSigned.
Another option is to open the module from the Administrative Tools folder in the Control Panel.
Active Directory Module in Administrative Tools
Windows Server 2008 R2 ^
If your Windows Server 2008 R2 machine is a domain controller, the PowerShell Active Directory Module is already installed. You only have to install the module on member servers. The procedure on Windows Server 2008 R2 is similar to that on Windows 7. (Note that the module is not available for Windows Server 2008.)
One difference is that you don't have to download RSAT because the tools are already available on Windows Server 2008 R2.
- In Server Manager, click Add features, and then:
- Select Active Directory module for Windows PowerShell in Remote Server Administration Tools > Role Administration Tools > AD DS and AD LDS Tools.
Alternatively, you can install the module from a PowerShell console:
Import-Module ServerManagerAdd-WindowsFeature RSAT-AD-PowerShell
After copying the module to your computer, you have to import it:
Or you can right-click the PowerShell icon on the taskbar and select Import system modules.
Import system modules
As on Windows 7, if you want to make the import permanent, you have to add the above import command to your PowerShell profile. Notice this description assumes you haven't updated PowerShell 2 on your Windows Server 2008 R2 machine (see the description about Windows 7).
Windows 8, Windows 8.1, Windows 10 ^
Things are a lot easier in Windows 8, Windows 8.1, and Windows 10. All you have to do is download and install RSAT (Windows 8, Windows 8.1, Windows 10). The installation enables all tools by default, and you also don't have to import the module. You can use the AD module right away after you install RSAT.
Windows Server 2012, Windows Server 2012 R2, Windows Server 2016 ^
As on Windows Server 2008 R2, the AD module is already installed on domain controllers on Windows Server 2012, Windows Server 2012 R2, and Windows Server 2016. On member servers, you can add the module as a feature in Server Manager.
- Start Server Manager.
- Click Manage > Add Roles and Features.
- Click Next until you reach Features.
- Enable Active Directory module for Windows PowerShell in Remote Server Administration Tools > Role Administration Tools > AD DS and AD LDS Tools.
Alternatively, you can install the module from a PowerShell console:
Installing the AD module on Windows Server 2012 with PowerShell
There's no need to import the Server Manager module first, as on Windows Server 2008 R2. You also don't have to import the AD module after the installation.
If you want to verify the successful installation of the module, you can just run the Get-ADuser cmdlet.
Install the AD module on PowerShell Core 6.x on a Windows computer ^
- Install RSAT with the method matching to your operating system (see sections above).
- Install the WindowsCompatibility module.
- Load the WindowsCompatibility module like usual with the Import-Module cmdlet
- Load the ActiveDirectory module with the Import-WinModule cmdlet
All versions: Import the ActiveDirectory module remotely ^
Create an interactive remote session
The simplest option is to create an interactive remote session to your domain controller with the Enter-PSsession cmdlet:
You can then work right away with the AD cmdlets. This option is good if you only occasionally manage AD on a PowerShell console and if you don't have to execute local scripts.
Managing Active Directory on PowerShell Core in an interactive remote session
Import the AD module from a remote session
The second option uses implicit remoting and allows you to run the AD cmdlets from a local session. However, you execute the AD cmdlets remotely on a domain controller. In practice, you won't notice much of difference in locally installed cmdlets. To import the AD module on PowerShell Core 6.0, execute these commands: