≡ Menu

How to Install the Active Directory Module for Windows PowerShell

With the release of PowerShell 2.0, we now have a PowerShell module that we can use to administer Active Directory. The Active Directory Module for Windows PowerShell runs on Windows Server 2008 R2 and on Windows 7 and relies on a web service that is hosted on one or more domain controllers in your environment. In this post I’ll go over what you need in order to install and use the Active Directory Module for PowerShell, also known as AD PowerShell.

Setting up your Domain Controllers

In order to use the Active Directory Module for Windows PowerShell on 2008 R2 and Windows 7, you first need to be running Active Directory Web Services (ADWS) on at least one Domain Controller. To install Active Directory Web Services (ADWS) you’ll need one of the following:

1. Windows Server 2008 R2 AD DS

You can load Active Directory Web Services (ADWS) on a Windows Server 2008 R2 Domain Controller when you install the AD DS role. The AD PowerShell module will also be installed during this process. Active Directory Web Services (ADWS) will be enabled when you promote the server to a DC using DCPromo.

2. Active Directory Management Gateway Service

If you cannot run Windows Server 2008 R2 Domain Controllers, you can install the Active Directory Management Gateway Service. Installing this will allow you to run the same Active Directory web service that runs on Windows Server 2008 R2 DC’s. You can download the Active Directory Management Gateway Service here. Make sure you read the instructions carefully, there are several hotfixes that need to be applied depending on the version of Windows you are running. You can install the Active Directory Management Gateway Service on DC’s running the following operating systems:

  • Windows Server 2003 R2 with Service Pack 2
  • Windows Server 2003 SP2
  • Windows Server 2008
  • Windows Server 2008 SP2

Note: You can also use AD PowerShell to manage AD LDS instances on Windows Server 2008 R2. If you plan on using AD LDS, Active Directory web services will be installed with the AD LDS role, the AD PowerShell module will also be installed during this process. The ADWS service will be enabled when your LDS instance is created.

Once you’ve got Active Directory web services up and running on your Domain Controller(s), you’ll notice you now have an ADWS service as shown here:

At this point, you should be ready to install the AD PowerShell module. You can run AD PowerShell on all versions of Windows Server 2008 R2 (except the Web Edition) and on Windows 7.

Installing the Active Directory Module for Windows PowerShell on 2008 R2 member servers

You can install the Active Directory Module on Windows 2008 R2 member servers by adding the RSAT-AD-PowerShell feature using the Server Manager. I usually use the ServerManager module to do this because it is quick and easy. To install the feature using the ServerManager module, launch PowerShell and run the following commands:

Import-Module ServerManager
Add-WindowsFeature RSAT-AD-PowerShell

Remember, this only needs to be done on Windows Server 2008 R2 member servers. The RSAT-AD-PowerShell feature will be added to 2008 R2 DC’s during the DCPromo process.

Installing the Remote Server Administration Tools (RSAT) feature on Windows 7

In order to install the Active Directory Module for Windows PowerShell you need to download the RSAT tools for Windows 7 here. Once this is installed you are still not finished, you need to enable the Active Directory module. Navigate to Control Panel > Programs and Features > Turn Windows Features On or Off and select Active Directory Module for Windows PowerShell as show here:

Once you have Active Directory web services running on at least one domain controller and the AD PowerShell module is installed, you are ready to run the AD PowerShell module. You can do this in one of two ways. First, you can access the “Active Directory Module for Windows PowerShell” shortcut in Administrative Tools as shown here:

Right click the shortcut and select “Run as administrator” in order to start PowerShell with elevated permissions.

You can also simply import the AD PowerShell module in your existing PowerShell session. Just use the Import-Module ActiveDirectory command:

Import-Module ActiveDirectory

That’s all that needs to be done to get up and running…I will get into using the AD PowerShell cmldets in future posts so keep an eye out for that.

14 comments… add one

  • Sunil December 6, 2010, 1:39 pm

    I have followed all the steps above for my Windows 7 machine but still I’m getting the below error.

    PS C:\> import-module ActiveDirectory
    Import-Module : Cannot find drive. A drive with the name ‘ C’ does not exist.
    At line:1 char:14
    + import-module <<<< ActiveDirectory
    + CategoryInfo : ObjectNotFound: ( C:String) [Import-Module], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

    Please help in solving this….

    Thanks,
    Sunil

  • c June 21, 2011, 8:59 am

    is it possible to import the activedirectory module into the exchange management shell as a snapin so i can access cmdlets from both libraries in the same session?

  • Mike Pfeiffer June 21, 2011, 6:01 pm

    Yeah you could. If you have the RSAT tools installed and the AD PowerShell module, you can just do a import-module activedirectory right in the Exchange Management Shell. You could evenly do it using remoting…for example, you could import the AD cmdlets from a 2008 R2 domain controller, and then the Exchange 2010 cmdlets from an Exchange server into your PowerShell session.

  • GeorgeC August 19, 2011, 9:03 am

    Any idea how I can load the module on the start-up of the session. I have tried adding import-module ActiveDirectory to different spots in the shortcut for the Exchange Management Shell but none of them seem to work.

  • Mike Pfeiffer August 20, 2011, 2:31 pm

    Add the import command to your PowerShell profile. Or, if you want to add it to the existing EMS shortcut, use this as the target:

    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -command “. ‘C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1′; Connect-ExchangeServer -auto ; Import-Module ActiveDirectory”

  • Reidar July 27, 2011, 11:30 pm

    Is there an ActiveDirectory module for PS available for Vista? My contracter is one of those who rolled it out on an enteprise level, and it would be practical to have a good Active Directory management tool available on my workstation, rather than having to remote into a server to do administration there.

  • Mike Pfeiffer July 28, 2011, 9:37 pm

    With PowerShell v2 installed on Vista, you can use implicit remoting. See if this helps:

    http://www.windowsitpro.com/blog/powershell-with-a-purpose-blog-36/scripting-languages/powershell-implicit-remoting-never-install-a-module-again-137373

    This would allow you to run the AD cmdlets from your 2008 R2 DC remotley. Also, you might want to check out the Quest AD cmdlets:

    http://www.quest.com/powershell/activeroles-server.aspx

  • Ganesan K August 5, 2011, 10:28 pm

    Dear Mike,

    you are great, i searched for this article lot time. i found in your site.. keep posted like this.

    Thanks,

    Ganesan K
    TechHowKnow

  • Constantine January 11, 2012, 8:44 am

    Thanks for the post, using Powershell from my workstation is 20 time better than going to the server.

  • Sonny January 27, 2012, 7:27 am

    I frequently look around for good ways to ensure that the AD tools are installed for powershell during scripts… Usually I open with an IF statement to attempt to load the AD module and if failed, instruct the user to install remote AD tools… something like this will work for people if you are also looking for a quick way to ensure AD module for powershell is running:

    $checkme = get-module|? {$_.name -eq “activedirectory”}|select Name
    if($checkme -ne “activedirectory”){
    try{import-module activedirectory}
    catch{“you do not have AD module local to load… please confirm you have Remote AD tools: Add-WindowsFeature RSAT-AD-PowerShell”}
    }

  • Mike Cloud March 20, 2012, 9:53 am

    @Sonny – Brilliant!! Thanks for posting that solution. You fixed an issue that I was having with an automated script!!!!!! :-)

  • Chennai MCSE April 12, 2013, 5:51 am

    Dear Mike,

    That was a great help. Want to try this in Windows 2012 Server also.

    I am not sure whether these commands will work inside Windows Server 2012. Will check it after installing Windows Server 2012.

    Thanks a lot for great tutorials.

    Chennai MCSE

  • Mike Pfeiffer April 12, 2013, 11:57 am

    Yes, there are lots of similarities and a ton of new cmdlets. Check out http://technet.microsoft.com/en-us/library/hh801904.aspx

  • Andy February 9, 2014, 10:48 am

    Hi,

    I have a Windows 2003 domain and have installed the AD web services successfully, but it is not workfin form a Windows 2008 memeber server.

    I just can’t get Windows Powershell with Active Directory Module to work on a Windows 2008 member server, I get this message:

    WARNING: Error initializing default drive: ‘Unable to find a default server
    with Active Directory Web Services running.’.

    I’ve installed a hotfix that was suppose to help Win 7 and 2008 machines to which didn’t help.

    On the DC I ran this:

    C:\Documents and Settings\admin-dc>sc query adws

    SERVICE_NAME: adws
    TYPE : 10 WIN32_OWN_PROCESS
    STATE : 4 RUNNING
    (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
    WIN32_EXIT_CODE : 0 (0×0)
    SERVICE_EXIT_CODE : 0 (0×0)
    CHECKPOINT : 0×0
    WAIT_HINT : 0×0

    C:\Documents and Settings\admin-dc>

    Do I need to run it on all of the DCs?

    Thanks

Leave a Comment