Import-Module Active Directory

When importing the active directoy module and then packaging as an EXE the import hangs and then times out.

Build Log:

VERBOSE: Checking license
VERBOSE: OutputPath is C:\Users\mahers\OneDrive - ****************************************\Documents\Dev\Powershell\out
VERBOSE: Bundling C:\Users\mahers\OneDrive - ****************************************\Documents\Dev\Powershell\Service Desk User Tool.ps1
VERBOSE: Parsing file C:\Users\mahers\OneDrive - ****************************************\Documents\Dev\Powershell\Service Desk User Tool.ps1.
VERBOSE: Found module import 'Import-Module ActiveDirectory' at 0
VERBOSE: Packager PSModulePath: C:\Users\mahers\OneDrive - ****************************************\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules;c:\Users\mahers\.vscode\extensions\ms-vscode.powershell-2021.12.0\modules;C:\Users\mahers\PowerShellProTools\2022.2.1\windows\..\Modules
VERBOSE: Replacing module ActiveDirectory
VERBOSE: Packaging C:\Users\mahers\AppData\Local\Temp\Service Desk User Tool.ps1
VERBOSE: Creating temp directory: C:\Users\mahers\AppData\Local\Temp\6bcdab3c9b0647df8468de634b816af7
VERBOSE: Packaging modules...
VERBOSE: Checking dotnet version.
VERBOSE: Checking dotnet SDK version.
VERBOSE: 6.0.200

VERBOSE: .NET SDK Version: 6.0.200

VERBOSE: Creating package project.
VERBOSE: Using .NET Framework version: net462
VERBOSE:   Determining projects to restore...
  Restored C:\Users\mahers\AppData\Local\Temp\6bcdab3c9b0647df8468de634b816af7\Service Desk User Tool.csproj (in 73 ms).

VERBOSE:   Determining projects to restore...
  Restored C:\Users\mahers\AppData\Local\Temp\6bcdab3c9b0647df8468de634b816af7\Service Desk User Tool.csproj (in 73 ms).

VERBOSE: Packaging C:\Users\mahers\AppData\Local\Temp\Service Desk User Tool.ps1 -> C:\Users\mahers\OneDrive - ****************************************\Documents\Dev\Powershell\out\Service Desk User Tool.exe
VERBOSE: Microsoft (R) Build Engine version 17.1.0+ae57d105c for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
  Service Desk User Tool -> C:\Users\mahers\OneDrive - ****************************************\Documents\Dev\Powershell\out\Service Desk User Tool.exe

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.02

VERBOSE: Microsoft (R) Build Engine version 17.1.0+ae57d105c for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
  Service Desk User Tool -> C:\Users\mahers\OneDrive - ****************************************\Documents\Dev\Powershell\out\Service Desk User Tool.exe

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.02

VERBOSE: Output: C:\Users\mahers\OneDrive - ****************************************\Documents\Dev\Powershell\out\Service Desk User Tool.exe

When I run the EXE i get this for a few mins then it times out.

The code is using Import-Module ActiveDirectory

Does anyone have any ideas why this happening?

Unfortunately, nothing come to mind immediately. I tried to replicate your issue but everything worked as expected. I am assuming you are on a 64-bit Windows 10 workstation.

Some questions

  1. Have you tried importing a different module? Do we know if this issue is limited to only the ActiveDirectory module?

  2. Can you try replacing “Import-Module ActiveDirectory” with “using module ActiveDirectory” at the top of your script? This is a long-shot since I did not need to do this on my system but perhaps this could help[1].

  3. This shouldn’t be needed but can you try running the exe from a verified elevated prompt?

  4. Does the system which you ran the executable on have KB2693643 installed? (RSAT)

  5. Is everything targeted for 64-bit? Is the RSAT tool 64-bit?

[1] See About_Using