Why does Import-Module create .psd1 and .psm1 files in AppData\Local\Temp?

826 views Asked by At

I have a binary module (MyModule.dll and accompanying MyModule.psd1) installed in Documents\PowerShell\Modules. In the .psd1 file, a subset of the functions are exported using the FunctionsToExport key.

When I use Import-Module to import it into the current session, MyModule.psm1 and MyModule.psd1 are created in AppData\Local\Temp. The .psm1 file contains no actual code (this is good, as I don't want the code exposed in plaintext). Its contents are just some boilerplate text that I didn't create:

# Internal PowerShell function. Use F5 for debugging internal functions. F10 or F11 (single step) is not supported.

The issue is this new MyModule.psd1, which has some of the data from my installed .psd1 but notably lacks the FunctionsToExport key. As a result, all functions are exported into the session. Further, when I use Get-Module, I see both a binary module and a script module listed. For example:

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     0.0.11.0              MyModule                            {Function1, Function2, Fu…
Binary     0.0.11                MyModule

What I want is to import my binary module and have a single module imported into the session that only exports the commands I have defined in the installed psd1 file. I don't want these AppData\Local\Temp versions.

Can anyone explain to me what is happening here and how I can achieve my goal? I have read a bit about PowerShell Compatibility (https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_windows_powershell_compatibility?view=powershell-7), but I don't think it should apply because:

  1. The module isn't installed in %windir%\system32\WindowsPowerShell\v1.0\Modules.
  2. I have CompatiblePSEditions = @('Core') defined in my installed .psd1 manifest.

I'm at a loss at this point. Thanks in advance for pointers in the right direction.

0

There are 0 answers