Functions not working from Module included in Environment

Product: PowerShell Universal
Version: 1.5.11

I have created an environment.
New-PSUEnvironment -Name "WBG" -Path "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -Modules @('WBGamesLogging') -Variables @('*')

I am including in a dashboard.
New-PSUDashboard -Name 'Tools' -BaseUrl '/tools' -Framework 'UniversalDashboard:Latest' -Environment "WBG" -Content {....

I see it’s loaded in the logs.
[2021-02-10T11:59:53.9219491Z] Loading module: C:\Program Files\WindowsPowerShell\Modules\WBGamesLogging\WBGamesLogging.psd1

But when I use functions from the module they don’t work and the log shows.

[2021-02-10T11:59:59.4849782Z] An error occurred: The term 'New-Log' 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.
Endpoint: 12bd7798-9f59-407f-9a70-529b2536d834
Session: 7527c0a7-3725-4bab-b706-b138cbc35f52
File: 
Endpoint Start Line: 4
Endpoint End Line: 11
Stack Trace: at <ScriptBlock>, <No file>: line 7
 
[2021-02-10T11:59:59.4856871Z] An error occurred: The term 'Write-Log' 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.
Endpoint: 12bd7798-9f59-407f-9a70-529b2536d834
Session: 7527c0a7-3725-4bab-b706-b138cbc35f52
File: 
Endpoint Start Line: 4
Endpoint End Line: 11
Stack Trace: at <ScriptBlock>, <No file>: line 8

The functions are exported in the .psm1
Export-ModuleMember -Function "Move-Log, New-Log, Write-Log"

Not sure what I am doing wrong here.

I also have the functions listed in the .psd1

# Functions to export from this module
FunctionsToExport = @(
'Move-Log'
'New-Log'
'Write-Log'
)

Try adjusting Export-ModuleMember like this:

Export-ModuleMember -Function @("Move-Log", "New-Log", "Write-Log")

When I had it like your example it didn’t export them for me.

PS C:\Users\adamr\Desktop> Get-Command -Module module

PS C:\Users\adamr\Desktop> ipmo C:\Users\adamr\Desktop\module.psm1 -force

PS C:\Users\adamr\Desktop> Get-Command -Module module


CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Function        Move-Log                                           0.0        module
Function        New-Log                                            0.0        module
Function        Write-Log                                          0.0        module

I did not try this with a PSD1.

ok that did it :slight_smile:

1 Like