-4

Please note: Because this is a self-answered question, there is no solution attempt in the question itself.

In my PowerShell scripts I'm using the ActiveDirectory module, which contains the various *-AD* cmdlets such as Get-ADUser.

How can I automate (script) the installation of the ActiveDirectory module on Windows 11?

The answer isn't straightforward, for the reasons detailed in the next section:

Note:

  • This question is on-topic for this site, because it meets 2 of the 3 criteria (whereas meeting only 1 is sufficient): It is about "software tools commonly used by programmers" and it is also about "a specific programming problem" namely how to perform installation of a specific software tool of interest programmatically.

The ActiveDirectory module does not ship with PowerShell, but - unlike most publicly available modules - its on-demand installation can not be scripted via the usual cmdlets, Install-Module or its successor, Install-PSResource, from their (default) repository, the PowerShell Gallery, because the module isn't available there.

Instead, the module is part of the larger, non-PowerShell-specific set of RSAT tools, which comprise many additional components.
(How these tools must be installed has changed over time; there are many older question relating to previous Windows versions that no longer apply; similarly, questions relating to server versions of Windows do not apply, as the installation method differs; there's no question specifically about scripting the installation that I am a aware of.)

The ActiveDirectory PowerShell module documentation as of this writing only provides an abstract pointer (emphasis added):

Starting with Windows 10 October 2018 Update, RSAT is included as a set of Features on Demand right from Windows 10 [and therefore also in Windows 11]. Now, instead of downloading an RSAT package you can just go to Manage optional features in Settings and click Add a feature to see the list of available RSAT tools. Select and install the specific RSAT tools you need.

  • That is, it only mentions a GUI installation and method and even for that it doesn't actually state which tool(s), specifically, you need to select to install the PowerShell module (only).
1
  • The question is about installation of a component required for software development (PowerShell scripting) and therefore on-topic for this site. This site is filled with similar questions that aren't closed. It should therefore be reopened. Commented 21 hours ago

1 Answer 1

2

Note:

  • Both installation methods require elevation, i.e. running with administrative privileges, and should work in (the now out-of-support) Windows 10 as well as in Windows 11.

    • If neither method works, the implication is that you're either running a pre-Windows 10 desktop edition of Windows, or a desktop edition that doesn't come with the RSAT tools.
  • Server editions of Windows require a different installation method, which is (also) covered in this helpful woshub.com article.


Programmatic (scripted) installation:

The installation can be scripted via the cmdlets of the Dism module:

#Requires -RunAsAdministrator
Get-WindowsCapability -Name Rsat.ActiveDirectory.DS-LDS.Tools* -Online |
  Add-WindowsCapability -Online

Note:

  • The use of wildcard expression Rsat.ActiveDirectory* to match the component of interest avoids the need to spell the exact name out in full, which would require hard-coding a version number, which you can alternatively do; e.g.:

    Add-WindowsCapability -Online -Name Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0
    
  • The -Online switch specifies that the operation should be performed on the currently running operating system (as opposed to an offline operating-system image); it is unrelated to downloading from the internet.


For the sake of completeness:

GUI-based installation:

Note: The name of the relevant feature was gleaned from the RSAT tools documentation.

  • Open the Start Menu and search for Optional Features; the first hit should take you directly to the relevant page in the Settings app.

  • Click on the View Features button - this will trigger a UAC authorization prompt (prompting for elevation)

  • Click on the See available features link.

  • Scroll down to the RSAT: Active Directory Domain Services and Lightweight Directory Services item or type the name (or a distinctive substring thereof) into the search textbox to locate it, then click the entry's checkbox and click Add (1).

    • Here's a screenshot from this helpful woshub.com article; while it is slightly outdated relative to the current Windows 11 experience, it is similar enough:

      • Active Directory module installation
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.