Importing Modules

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 4 years and 8 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
User avatar
Reddrgn2
Posts: 49
Last visit: Wed Nov 08, 2023 10:34 am
Answers: 1

Importing Modules

Post by Reddrgn2 »

Product, version and build: Primal Studio 2019
32 or 64 bit version of product: 64
Operating system:win 10 pro
32 or 64 bit OS: 64

I have tried to search before creating this topic, cause I am sure i missed something somewhere.

Issue - when trying to run a few basic built exe's they open with no issue but doing the actual work (getting the info) they fail on other user computers.

I build 2 gui's to get basic AD user info, one looks at emp number and the second looks at display name. It get name, title, emp#, upn, description.

I built them for practice and whiny people complaining about having to open "AD users and computers, then searching"

I have tested them on my computer and work fine. I have tested on a pc used for testing, works fine.

A few users are not able to get them to display results, just shows the loading page.

I have tried a few options to get it to work.

Try 1 - when opening the exe(built exe as powershell- v2 host windows forms for either 32 or 64b, no restrictions on os), it runs import-module activedirectory
-works on my and testing - other pc's half the people it works

Try 2 - on the form i created another button to run import-module activedirectory - (built exe as powershell- v2 host windows forms for either 32 or 64b, no restrictions on os), it runs import-module activedirectory
-works on my and testing - other pc's half the people it works

One of my questions is - for the button to import the AD module - should there be anything else with the command? Any ideas that I might be missing or didn't do correctly? I would like to have all the users that will be using the tools upgrade their powershell versions to 5 but thats another issue to deal with. Right now most are at PS version 2. Side note, testing pc is win 7(64b, ps version 2)-able to run gui's, another win 10(64b, ps version 5.1)-not able to really run gui's.

Here is the code for the form with the button
  1. $formGetEmpInfoFromDispla_Load={
  2.     #TODO: Initialize Form Controls here
  3.     #Import-Module ActiveDirectory
  4. }
  5.  
  6. $buttonFind_Click={
  7.     #TODO: Place custom script here
  8.     $displayname = $textboxdisplayname.Text
  9.     $labelDisplayUserInfo.Text = Get-ADUser -Filter "name -like '$displayname'" -Properties Name, SAMAccountName, Enabled, description, title, SID, UserPrincipalName, employeeID, ScriptPath, HomeDirectory | Format-List -Property Name, SAMAccountName, EmployeeID, Enabled, Description, Title, UserPrincipalName, ScriptPath, HomeDirectory, SID | Out-String
  10.    
  11. }
  12.  
  13. $buttonLoadADModule_Click={
  14.     #TODO: Place custom script here
  15.     Import-Module ActiveDirectory
  16. }
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Importing Modules

Post by davidc »

[TOPIC MOVED TO POWERSHELL GUIS FORUM BY MODERATOR]
David
SAPIEN Technologies, Inc.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Importing Modules

Post by davidc »

For the Windows 10 machines, I recommend generating a package executable engine targets V5 and see if that works.

I also recommend using the PassThru parameter to verify that the module was indeed loaded:

Code: Select all

$module = Import-Module ActiveDirectory -PassThru

if (-not $module)
{
	#Show error message
}
David
SAPIEN Technologies, Inc.
User avatar
Reddrgn2
Posts: 49
Last visit: Wed Nov 08, 2023 10:34 am
Answers: 1

Re: Importing Modules

Post by Reddrgn2 »

Building both for PS version 5 worked for the windows 10.

PC's with PS version 2 still having issues, even though built for PS version 2 - it not all but some .

Added the pass though and not giving error one that it does not work on, just sits there.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Importing Modules

Post by jvierra »

Start by just running the script on the machines that fail and look at the scripts result. You are likely getting an error that you cannot see.
This topic is 4 years and 8 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