Import-Module when EXE-packaged

Archived support forum for customers who once purchased a PrimalForms product license. This forum is locked.
This topic is 12 years and 1 month 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.
User avatar
mssapien
Posts: 23
Last visit: Fri Oct 23, 2015 1:27 am

Import-Module when EXE-packaged

Post by mssapien »

Import-Module gives access to cmdlets when PS1-scripted, but not when EXE-packaged. What do I have to do so that the module gets imported and I can its cmdlets even when the script or project is packaged and run as an EXE?
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Import-Module when EXE-packaged

Post by davidc »

The packaged exe should import-modules as long as you call the Import-Module cmdlet and the module isn't host specific. You also have to make sure the Module is installed in whatever system you run the exe. David
David
SAPIEN Technologies, Inc.
User avatar
mssapien
Posts: 23
Last visit: Fri Oct 23, 2015 1:27 am

Import-Module when EXE-packaged

Post by mssapien »

It does not work. Try exporting the following script package to an EXE and run it on a Windows Server 2008 R2, and you will see that c:command.txt gets created since it is an innate cmdlet to PowerShell, while c:windowsfeatures.txt does not get created since it is dependent on the module ServerManager. Running the code manually in PowerShell creates both files.Import-Module ServerManagerGet-WindowsFeature > c:windowsfeatures.txtGet-Command > c:commands.txt
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Import-Module when EXE-packaged

Post by Alexander Riedel »

Are you getting an error message when using Import-Module?
If so, what does it say?

Are you packaging as a 32 bit exe and running in a 64 bit shell otherwise?
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
mssapien
Posts: 23
Last visit: Fri Oct 23, 2015 1:27 am

Import-Module when EXE-packaged

Post by mssapien »

The EXE just silently runs with no error messages. It did not help to package the EXE as 32-bits instead of 64-bits, or with elevation rights.I updated the code to this:try { Import-Module ServerManager Get-WindowsFeature > c:windowsfeatures.txt Get-Command > c:commands.txt} catch { $_ > c:exception.txt}c:exception.txt gets created with this message, which shows that the Import-Module did not work:The term 'Get-WindowsFeature' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.At line:28 char:20+ Get-WindowsFeature <<<< > c:windowsfeatures.txt + CategoryInfo : ObjectNotFound: (Get-WindowsFeature:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Import-Module when EXE-packaged

Post by Alexander Riedel »

Usually the Import-Module would fail with an error message if the module is not there or cannot be loaded.

If you leave the output redirection out, do you get any output if packaged?

Import-Module ServerManager
Get-WindowsFeature
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
mssapien
Posts: 23
Last visit: Fri Oct 23, 2015 1:27 am

Import-Module when EXE-packaged

Post by mssapien »

I tried that code, but still no messagebox or something of information appears. test.exe runs silently for a brief moment and then exits, as shown in task manager.Absolute path did not work either:Import-Module C:Windowssystem32WindowsPowerShellv1.0ModulesServerManagerServerManager.psd1I am using PrimalForms 2011 Version 2.0.20 (newest)
User avatar
mssapien
Posts: 23
Last visit: Fri Oct 23, 2015 1:27 am

Import-Module when EXE-packaged

Post by mssapien »

Sorry, I may have misunderstood your instructions. I thought you were speaking about the 64-bit vs 32-bit choice in the Home tab. I found a similar option in the dialog box when building EXE, and when I selected 64-bit there, it worked.
This topic is 12 years and 1 month 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.