Use the Active Directory PowerShell module without installing RSAT

During the creation of a new custom Azure Devops extension for one of my customers, I bumped into the challenge of querying Active Directory. This had to be done on any of the many build servers, but installing Remote Server Administration Tools (RSAT) on every build server was not an option. Therefore the AD PowerShell module has to be imbedded into the task itself.

The usual way of doing this ask for a simple copy/paste of the PowerShell module. PowerShell modules are placed in either your profile, the PowerShell directory in Windows or in Program files. The easiest way to find these location is ask Powershell with the following command

$ENV:PSModulePath

I went to a server where RSAT was installed and found the module in the ‘C:\Windows\System32\WindowsPowerShell\v1.0\Modules‘ directory. The first step is to copy the ActiveDirectory folder to a new location. In my case E:\Temp.

Unfortunately we aren’t done yet, because the module requires two extra library files to function. Go to C:\Windows\WinSxS and copy the following files to your module folder:
– Microsoft.ActiveDirectory.Management.dll
– Microsoft.ActiveDirectory.Management.resources.dll

Without these modules, you will end up with an error that says the file or assembly Microsoft.ActiveDirectory.Management.dll cannot be found.

Your module folder should look like this after copying both the PowerShell activedirectory folder and the two dll files:

While it is common do import the PSD1 or PSM1 file to import a module, for Active Directory we are importing the extra added DLL.

Import-Module .\ActiveDirectory\Microsoft.ActiveDirectory.Management.dll"
Get-AdUser -identity <username>

I have not tested the full module, but the cmdlets that are required for my script, Get-Aduser and Get-AdGroupMember are working like a charm.

Do not use this solution when you are using it for scripts to administer your Active Directory. This is a solution for simple GET queries but it is not supported by Microsoft.