amaru96
Posts: 3
Joined: Mon Mar 02, 2015 12:22 am

Add new PowerShell modules as part of install

Thu Dec 12, 2019 11:12 am

Hi guys,

I have some powershell modules I'd like to install as part of the installer. If I manually copy the modules into the C:\Program Files\WindowsPowerShell\Modules folder, everything works fine and I can import and use the modules.

So I created an installer and used the custom actions with a PowershellScriptInline action which copies the files into the same folder as above. This works fine too, the modules are copied into the correct folder.

However, they do not work. I cannot import them.

Not sure why this is the case, or if I'm missing some kind of setting?

Catalin
Posts: 6542
Joined: Wed Jun 13, 2018 7:49 am

Re: Add new PowerShell modules as part of install

Thu Dec 12, 2019 4:53 pm

Hello,
However, they do not work. I cannot import them.
Could you please give me some more details about what you mean by "I cannot import them"? Do you get any errors? If so, could you please let me know if this is the error that you are encountering?

Import-Module : The specified module 'YourModule' was not loaded because no valid module file was found in any
module directory.
At line:1 char:1
+ Import-Module YourModule
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (YourModule:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

If that is not the case, please forward me a screenshot of the error so I can further investigate this.

Looking forward to hearing from you.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

amaru96
Posts: 3
Joined: Mon Mar 02, 2015 12:22 am

Re: Add new PowerShell modules as part of install

Fri Dec 13, 2019 10:05 am

When I manually copy the modules into the folder I can run the below command and it lists all the modules with that name.

get-module -name <module name> -listallavailable

I can also import-module <module name> and it works fine.

But, when I have them copied into the module folder as part of the installer, neither command works.

get-module -name <module name> -listallavailable shows no results

And when I try to import-module it doesn't find it and throws an error like you listed.
The specified module 'YourModule' was not loaded because no valid module file was found in any
module directory.

Catalin
Posts: 6542
Joined: Wed Jun 13, 2018 7:49 am

Re: Add new PowerShell modules as part of install

Fri Dec 13, 2019 2:19 pm

Hello,

Thank you for your followup on this.
And when I try to import-module it doesn't find it and throws an error like you listed.
In your first thread, you mentioned that you are using a PowerShell script to copy the files into the right directory, am I right?

If so, could you please forward me a copy of the .AIP file that you are using to build your project so I can further investigate it?

From the tests that I've performed yesterday when I posted the reply, the error was caused by the file redirection.

In order to install the modules, I have recreated the file hierarchy in the "Files and Folders" page, like this:
FolderHierarchy.png
FolderHierarchy.png (121.45KiB)Viewed 2312 times

The ProgramFiles folder can be resolved, at install time, into two folders:

C:\Program Files --> if the process is of 64-bit type

C:\Program Files (x86) --> if the process is of 32-bit type on a 64-bit machine

Therefore, our path to the modules could either be:

Code: Select all

C:\Program Files\WindowsPowerShell\Modules
or

Code: Select all

C:\Program Files (x86)\WindowsPowerShell\Modules
If you manually open the directories, you will notice that both of them have the "WindowsPowerShell\Modules" folder.

Additionally, as you may know, PowerShell comes in two versions - 32-bit one and respectively 64-bit one (on a 64-bit machine).

What I have noticed is the following:

If you install the modules in the 64-bit folder (e.g. C:\Program Files\WindowsPowerShell\Modules) and then open the 32-bit PowerShell and try to get the module, you will get the error specified in my first thread.

The same happens the other way around (if you install it in the 32-bit folder and then open the 64-bit PowerShell, trying to import the module)

I think that this might have happened on your machine as well.For instance, if your package type is of 32-bit and the PowerShell used to copy the files is of 32-bit, chances are that your files were copied on the "Program FIles (x86)" folder. Therefore, when trying to import the modules from a 64-bit instance of PowerShell, the error is thrown.

Hope this explanation helps.

Looking forward to hearing from you.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”