Home Powershell Activity

Error Using ActiveDirectory PowerShell Module

Nick_FlintNick_Flint Customer Advanced IT Monkey ✭✭✭

I have a PSA that calls ScriptA which acts as a traffic director. ScriptA inports the ActiveDirectory module. Based on the template ID ScriptA calls the associated ScriptB. In ScriptB I'm trying to use the Get-ADUser command:

 # $ADUser = Get-ADUser -LDAPFilter "(SamAccountName=$AffectedUserUserName)" -Properties *


    $ADUser = Get-ADUser -Filter {SamAccountName -eq $AffectedUserUserName}

   } catch {

    $_ | Out-File -LiteralPath 'e:\logs\errormsg.txt' -Append


This results in this error:

Get-ADUser : The 'Get-ADUser' command was found in the module 'ActiveDirectory', but the module could not be loaded. 

For more information, run 'Import-Module ActiveDirectory'.

I can log into the workflow server as the service account and run these scripts manually and they process correctly without error. The error only occurs when the PSA runs as part of a SR activity workflow.

Any ideas on what could be wrong?


  • Brian_WiestBrian_Wiest Customer Super IT Monkey ✭✭✭✭✭

    I add this to the top of every PS script. It checks to make sure the module is loaded as part of that session.

    if ( !(Get-Module -Name ActiveDirectory -ErrorAction SilentlyContinue) ) {Import-module ActiveDirectory}
  • Nick_FlintNick_Flint Customer Advanced IT Monkey ✭✭✭

    Here's how I was doing it:

    if (-not (Get-Module -Name Import-Module ActiveDirectory)) {

      Import-Module ActiveDirectory -ErrorAction Stop


    I switched over to your code and get the same error.

  • Brian_WiestBrian_Wiest Customer Super IT Monkey ✭✭✭✭✭

    I found this was the only method that allowed the PS scripts to run successfully (at least for my environment)

    Made sure the SCSM Service account has rights to the AD module.

  • Thorsten_MewesThorsten_Mewes Customer IT Monkey ✭

    Hi @Nick_Flint , we are getting the same error but with VSTeam-Module instead. Ever found a working solution to this?

  • Nick_FlintNick_Flint Customer Advanced IT Monkey ✭✭✭

    @Thorsten_Mewes Unfortunately not. I had to resort to other methods to achieve what I was trying to do.

  • Adam_DzyackyAdam_Dzyacky Product Owner Contributor Monkey ✭✭✭✭✭

    Hey @Thorsten_Mewes and/or @Nick_Flint. Could you share a bit more about:

    • Your workflow server e.g. the modules you know for a fact are installed, PS version, etc.
    • Is it just the AD module, several, or any?
    • Version of PSA
    • Are you running in a separate process/different user?
    • For Nick - could you share perhaps a distilled version of your "ScriptA which acts as a traffic director" scenario you're referring to? There are a few ways I could see you pulling this off, but I don't want to assume.

    I just did a quick test again of running the AD module within an SR and managed to interact with Get-AD User/Computer/Group as expected. I'm running:

    • PSA
    • Server/SCSM 2019
    • Not running as a different user or in a different process space

Sign In or Register to comment.