Import-Module when EXE-packaged
Import-Module when EXE-packaged
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?
Import-Module when EXE-packaged
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.
SAPIEN Technologies, Inc.
Import-Module when EXE-packaged
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
- Alexander Riedel
- Posts: 8479
- Last visit: Thu Mar 28, 2024 9:29 am
- Been upvoted: 37 times
Import-Module when EXE-packaged
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?
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.
SAPIEN Technologies, Inc.
Import-Module when EXE-packaged
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
- Alexander Riedel
- Posts: 8479
- Last visit: Thu Mar 28, 2024 9:29 am
- Been upvoted: 37 times
Import-Module when EXE-packaged
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
If you leave the output redirection out, do you get any output if packaged?
Import-Module ServerManager
Get-WindowsFeature
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Import-Module when EXE-packaged
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)
Import-Module when EXE-packaged
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.