Cannot load AD module into powershell script

2.7k views Asked by At

I am working on a program for my company that requires an check function on the user's username, which requires the AD module to be installed ONLY when the program is opened. It works fine on my PC, but I am an admin and I run Windows 10. The rest of my environment is Windows 7.

My code:

Import-Module "\\FileServer\common\IT\Powershell\Modules\ActiveDirectory"

The error:

Import-Module: Could not load file or assembly 'file://\\bmh01-fs03\common\IT\Powershell\Modules\ActiveDirectory\Microsoft.ActiveDirectory.Management' or one of its dependencies. The ststem cannot find the file specified.

Is it something within the AD module? And why does it work on my PC and not a users?

2

There are 2 answers

0
vrdse On BEST ANSWER

The ActiveDirectory module is a non redistributable module. It comes as part of the Remote Server Administration Tools (RSAT), which you have to install on the client.

If you want to avoid such dependencies, you can query Active Directory with the [ADSI] provider.

0
SOS On

This actually works fine for me in standard PowerShell (just not PowerShell Core).

Transfer these directories from the server with the RSAT module:

C:\Windows\Microsoft.NET\assembly\GAC_64\Microsoft.ActiveDirectory.Management\v*\Microsoft.ActiveDirectory.Management.dll
C:\Windows\System32\WindowsPowerShell\v1.0\Modules\ActiveDirectory\

And import:

Import-Module "full_path\Microsoft.ActiveDirectory.Management.dll"
Import-Module "full_path\ActiveDirectory.psd1"