Import-Module when EXE-packaged

Archived support forum for customers who once purchased a PrimalForms product license. This forum is locked.
User avatar
mssapien
Posts: 23
Joined: Tue Jan 03, 2012 4:39 am

Import-Module when EXE-packaged

Post by mssapien » Wed Feb 15, 2012 10:56 pm

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
Joined: Thu Aug 18, 2011 4:56 am

Import-Module when EXE-packaged

Post by davidc » Thu Feb 16, 2012 3:12 am

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
Joined: Tue Jan 03, 2012 4:39 am

Import-Module when EXE-packaged

Post by mssapien » Thu Feb 16, 2012 6:25 pm

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: 7005
Joined: Tue May 29, 2007 4:43 pm

Import-Module when EXE-packaged

Post by Alexander Riedel » Thu Feb 16, 2012 6:40 pm

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
Joined: Tue Jan 03, 2012 4:39 am

Import-Module when EXE-packaged

Post by mssapien » Thu Feb 16, 2012 6:51 pm

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: 7005
Joined: Tue May 29, 2007 4:43 pm

Import-Module when EXE-packaged

Post by Alexander Riedel » Thu Feb 16, 2012 7:04 pm

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
Joined: Tue Jan 03, 2012 4:39 am

Import-Module when EXE-packaged

Post by mssapien » Thu Feb 16, 2012 7:08 pm

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
Joined: Tue Jan 03, 2012 4:39 am

Import-Module when EXE-packaged

Post by mssapien » Thu Feb 16, 2012 10:40 pm

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.