AD gui not importing module

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 1 year and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
Jwalkingjon
Posts: 2
Last visit: Mon Mar 18, 2024 12:49 pm

AD gui not importing module

Post by Jwalkingjon »

Hi All,

I wrapped my script into a EXE and it seems like until I manually open a separate PowerShell session and run a Import-module ActiveDirectory the GUI won't work at all. I even tried putting a Import-Module Activedirectory into a separate button click as a test and still no luck. Any ideas? The Import-Module is the first line in my code.
User avatar
Olga_B
Site Admin
Posts: 196
Last visit: Thu Mar 28, 2024 8:34 am

Re: AD gui not importing module

Post by Olga_B »

I need more information to better assist you.

Please answer the following:
What is your executable suppose to do?
What script engine are you using to build?
Does your project or script run in PowerShell Studio before packaging into an executable?
Are there any errors in the Event Viewer?
Jwalkingjon
Posts: 2
Last visit: Mon Mar 18, 2024 12:49 pm

Re: AD gui not importing module

Post by Jwalkingjon »

Olga_B wrote: Tue Dec 13, 2022 3:02 pm I need more information to better assist you.

Please answer the following:
What is your executable suppose to do?
What script engine are you using to build?
Does your project or script run in PowerShell Studio before packaging into an executable?
Are there any errors in the Event Viewer?
Hi it was built using Sapien Powershell V5 Host (WIndows Forms)
The exe is used to build accounts in AD, The GUI seems to work if I open another elevated PowerShell and manually run the Import-Module. It works for the rest of the day if I do that, Since I usually leave PowerShell open for the day. But it seems like the initial Import-Module command at the top of my script isn't running now that I've wrapped it in an exe.
I didn't see any errors in Event viewer relating to this.
The project works fine if I export it as a PS1 and run it or if I run it directly from Powershell studio, The issue happens after I wrap it to an EXE.

Also i'm running the exe elevated and exported it as V5 -64bit, It's just strange that the GUI works if I run an Elevated PowerShell and import the module manually and THEN open the GUI.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: AD gui not importing module

Post by Alexander Riedel »

There can be different things at play.
A) your import-module is not executed. Add a message box right after it to verify
B) The ActiveDirectory module (which one?) detects that it runs in a PowerShell console and
does nothing if it is not. Use Get-Module after the import to check if it was indeed imported.
C) The location you insert your import-module is not translated to generated code for the
executable. We don’t know if you are building a project, exporting code and packaging that or
something in between. Can you let us know where you insert that call?
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 1 year and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked