A prerequisite for just about every Active Directory task in Windows PowerShell is to install the Active Directory PowerShell module. This popular module allows administrators to quickly query and make changes to Active Directory with PowerShell.

In this blog post, we're going to dive into how to install the PowerShell Active Directory module on Windows 10. We'll then cover how to connect to AD with PowerShell and go into the various ways you can authenticate to AD.

Install RSAT (Remote Server Administration Tools)

Before we begin, whether you can use the PowerShell cmdlets to access ADDS depends on your variant of Windows and how old it is. If you are using a workstation variant of Windows (Professional, Education, Enterprise) then you will need to install the Remote Server Administration Tools (RSAT) package that is appropriate for your computer. If you are using a Server variant of Windows, then you will already have RSAT available.

If you don't have RSAT you'll get the annoying 'the term Get-AD* is not recognized as the name of a cmdlet, function, script file, or operable program' type messages when you attempt to run the commands we'll be covering.

RSAT for pre 1809 Windows 10

If you're on Windows 10 pre-build 1809, you'll need to download an RSAT package from the Microsoft. The install is simple and straightforward.

Learn how to find your Windows 10 build version here if you don't know how.

Once you have installed RSAT you will need to ensure the Active Directory Module for Windows PowerShell is enabled in Windows Features. By default, it should be already.

Enabling the Active Directory Module for Windows PowerShell
Enabling the Active Directory Module for Windows PowerShell

RSAT for post-1809 Windows 10

In versions of Windows from 1809 onwards the RSAT capabilities are available as optional features. There's no need to download an external packages.

To install the ActiveDirectory module on Windows 10 post-1809, use the Add-WindowsCapability cmdlet to enable the Rsat.ActiveDirectory.DS-LDS.Tools optional feature as shown below.

PS51> Add-WindowsCapability -Online -Name Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0

The above syntax was tested on Windows 10 Build 1903 and on Windows 7.

RSAT for Windows Server

On a server operating system you can use the PowerShell ServerManager module to enable the RSAT-AD-PowerShell feature in PowerShell.

PS51> Import-Module ServerManager
PS51> Install-WindowsFeature -Name RSAT-AD-PowerShell

Connecting and Authenticating

Once the ActiveDirectory module is set up, you'll then begin using the Active Directory PowerShell cmdlets.

Although the cmdlets interact with different parts of AD, you'll find nearly all of them have common parameters. Two of those parameters are Server and Credential.

Connecting to a Specific Active Directory Domain Controller

By default, the AD cmdlets will find a domain controller for you. However, if you need to connect to a different domain controller, you can use the Server parameter.

The Server parameter isn't mandatory. PowerShell will attempt to find a domain controller to connect to by default. The default domain controller to connect to is determined by trying the following in the listed order:

  1. Use the Server property of objects passed in on the pipeline.
  2. Use the server associated with the AD PowerShell provider drive, if in use.
  3. Use the domain of the client computer.

If you'd like to connect to a specific domain controller, you can do so by providing a value for the Server parameter. You can specify several different ADDS objects in different formats such as:

  • A domain name specified as a FQDN or NETBIOS name such as domain.local or DOMAIN
  • A domain controller specified as a FQDN or NETBIOS name such as server.domain.local or SERVER
  • A fully-qualified domain controller and port such as server.domain.local:3268

Connecting to Active Directory with Alternate Credentials

By default, the Active Directory PowerShell cmdlets will use a two-step process for determining the user account to connect to AD with.

  1. Use the credentials associated with the PowerShell AD provider drive, if the command is run from there.
  2. Use the credentials of the logged-on user.

But you can also specify alternate credentials using the Credential parameter.

The Credential parameter allows you to pass in a PSCredential object or, if you provide a username, you will be prompted for a password and these credentials will be used.

PS51> $credential = Get-Credential
PS51> Get-Aduser -Filter * -Credential $credential
Example usage of the Credential parameter

You also have two possible authentication types available, controlled by the AuthType parameter. These are Negotiate (the default) and Basic. Basic authentication is only possible over an SSL connection.

PS51> Get-Aduser -Filter * -Credential $credential -AuthType Negotiate|Basic
Authenticating using a non-default type

Summary

If you're logged onto a domain-joined computer with a domain account and a recent version of Windows 10, this process is easy. Setting up the PowerShell Active Directory module is a cinch because it will auto-discover the domain controller for you and use your logged-in credential.

But not all environments are the same. Everyone isn't that lucky! This post should give you everything you need to start managing Active Directory with PowerShell right away.

Further Reading