Udostępnij za pośrednictwem


Install the Active Directory PowerShell Module on Windows 10

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. You can imagine that we dogfood a lot of software as Microsoft employees, so it was well past time for a reload.

As part of this I had to set up the Active Directory module. Since the process was more than one quick step, I decide this deserves a script to help everyone else in the world as well. How many steps does it take?

  • Find and download the CPU-architecture-appropriate Windows 10 RSAT package (Remote Server Administration Tools)
  • Install the RSAT
  • Enable the Active Directory PowerShell feature
  • Update-Help for the AD module

This is mostly a one-time task, except for updating the module help. Generally I only script things that are more repeatable. However, I know many of you like to reload your laptop on a regular basis. I also know that lots of people are deploying Windows 10 right now. So this seemed like a good community service project.

The Script

This script needs to run from an elevated ISE or console session, since it is configuring your system. Obviously it will only run on Windows 10, because that is the goal.

Like any good PowerShell scripter I borrowed code from various sources on the internet. I included comments with the links where I found handy code for downloading a file, installing a hotfix, etc.

Rather than explain the entire script line-by-line, I’ll provide the interesting parts here with comments. DO NOT copy/paste/run the code below.  It is not complete. Use the download link at the bottom of this post to get a copy of the full script.

 #requires -RunAsAdministrator

# Is the OS Windows 10?
If ((Get-CimInstance Win32_OperatingSystem).Caption -like "*Windows 10*")

# Is the RSAT already installed?
If (Get-HotFix -Id KB2693643 -ErrorAction SilentlyContinue)

# Is this x86 or x64 CPU?
If ((Get-CimInstance Win32_ComputerSystem).SystemType -like "x64*")

# Download the hotfix for RSAT install
$WebClient = New-Object System.Net.WebClient
$WebClient.DownloadFile($URL,$Destination)
$WebClient.Dispose()

# Install the hotfix. No native PowerShell way that I could find.
# wusa.exe returns immediately. Loop until install complete.
wusa.exe $Destination /quiet /norestart /log:$home\Documents\RSAT.log
do {
    Write-Host "." -NoNewline
    Start-Sleep -Seconds 3
} until (Get-HotFix -Id KB2693643 -ErrorAction SilentlyContinue)

# Double-check that the role is enabled after install.
If ((Get-WindowsOptionalFeature -Online -FeatureName `
    RSATClient-Roles-AD-Powershell -ErrorAction SilentlyContinue).State `
    -eq 'Enabled') {

    Write-Verbose '---RSAT AD PowerShell already enabled'

} Else {

    Enable-WindowsOptionalFeature -Online -FeatureName `
         RSATClient-Roles-AD-Powershell
}

# Install the help
Update-Help -Module ActiveDirectory -Verbose -Force

# Optionally verify the install.
dir (Join-Path -Path $HOME -ChildPath Downloads\*msu)
Get-HotFix -Id KB2693643
Get-Help Get-ADDomain
Get-ADDomain

I turned this into a function with full help and verbose output. I always like watching the blue verbose scroll as PowerShell runs. You get that sense of satisfaction that everything in the world is good when you watch your own code perform. #nerdthrills

Download

You can find the code here on the TechNet Script Gallery. Enjoy!

Comments

  • Anonymous
    February 26, 2016
    Hey Ashley,

    I have a similar example that you may like as detailed in my blog post at http://blog.kilasuit.org/2015/11/16/quick-win-install-windows-10-rsat-tools-via-powershell/

    Let me know what your thoughts are

    Many thanks

    Ryan
  • Anonymous
    July 05, 2016
    Thank you thank you thank you.Worked like a charm first time.
  • Anonymous
    September 06, 2016
    at this time the windows powershell defaults to requiring the script be signed to run it...
  • Anonymous
    September 22, 2016
    Worked like a charm. Thanks
  • Anonymous
    October 16, 2016
    Thank you for sharingMake work with a simplest method. But I like the way your script is structured!
  • Anonymous
    November 17, 2016
    Thank you for this script! Worked flawlessly first time around on my Windows 10 machine and will save me much time in the future.
  • Anonymous
    January 24, 2017
    The script ran flawlessly on on PC, but on another, at the end, it hit:Enable-WindowsOptionalFeature : Feature name RSATClient-Roles-AD-Powershell is unknown.At D:\Scripts\install-ADmodule.ps1:129 char:9+ Enable-WindowsOptionalFeature -Online -FeatureName RSATClient ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Enable-WindowsOptionalFeature], COMException + FullyQualifiedErrorId : Microsoft.Dism.Commands.EnableWindowsOptionalFeatureCommandVERBOSE: ---Downloading help for AD PowerShellUpdate-Help : No Windows PowerShell modules were found that match the following pattern: ActiveDirectory. Verify thepattern and then try the command again.At D:\Scripts\install-ADmodule.ps1:134 char:5+ Update-Help -Module ActiveDirectory -Verbose -Force+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (ActiveDirectory:String) [Update-Help], Exception + FullyQualifiedErrorId : ModuleNotFound,Microsoft.PowerShell.Commands.UpdateHelpCommandIs there a fix or workaround? Thanks.
    • Anonymous
      February 09, 2017
      Probably you also need to run this to verify that reboot is not required after setup.If ((Get-HotFix -Id KB2693643).InstalledOn) { Write-Host "---It is really installed and reboot is not required."}If reboot is required, then "InstalledOn" should be empty.
    • Anonymous
      March 07, 2017
      I have also faced the following issue finally Enable-WindowsOptionalFeature : Feature name RSATClient-Roles-AD-Powershell is unknown.Just did a restart of my Windows 10 desktop. Once the desktop is back I have ran Enable-WindowsOptionalFeature -Online -FeatureName RSATClient-Roles-AD-Powershell from PS again. It worked fine thenAshley did a great job ! Looks Ashley need some minor changes in the script
  • Anonymous
    May 11, 2017
    After Windows Creators update you have to re-install the RSAT tools...
  • Anonymous
    June 01, 2017
    Excellent script. Thanks! Such a time saver.I edited the log suffix for uninstalls from .log to .evt since the log produced by wusa.exe is binary and can then be opened by event viewer
  • Anonymous
    February 05, 2018
    https://www.microsoft.com/en-us/download/details.aspx?id=45520 offers downloads of the new RSAT tools AFTER update 1709
    • Anonymous
      May 01, 2018
      Good info on the 1709 update needing a re-install of RSAT. My machine was recently updated and my scripts started failing. This is why.
  • Anonymous
    January 08, 2019
    Thanks for the informations. Helps