0

I have some PowerShell functions and I want to import them into my server 2008 R2 via command Import-Module. So I created a psd1 file and in psm1 I use: Export-ModuleMember -Function "*-*" -Alias *.

However when I execute command:

PS C:\Windows\system32> import-module Myloader -DisableNameChecking -Verbose
VERBOSE: Loading module from path 'C:\Tools\Myloader.psd1'.
VERBOSE: Loading module from path 'C:\Tools\Myloader.psm1'.

I expect it should import my functions but it does not and there is no errors shown up. Then I execute Get-Module -ListAvailable, my function is listed out but there is no information about ExportedCommands

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     3.0        MyLoader
Script     3.0        MyLoader

But when I run it on my local machine it is OK. Have anyone faced with this issue before?

This issue happens on Windows Server 2008 R2, PowerShell 5.0.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Phong Vo
  • 1,078
  • 7
  • 16

1 Answers1

0

When using a module manifest you do the exports inside the .psd1 file. Remove the Export-ModuleMember statement from your .psm1 file and make sure the .psd1 file contains the following lines:

ModuleToProcess   = 'MyLoader.psm1'
FunctionsToExport = '*-*'
AliasesToExport   = '*'
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • Thank you for your solution @Ansgar. I did the same with your suggestion but there is nothing change. – Phong Vo Aug 14 '15 at 04:20
  • @PhongVo Then you need to show the content of both your psm1 and psd1 file. Please edit your question to include that information. – Ansgar Wiechers Aug 14 '15 at 09:26