简体   繁体   中英

How to import a module with a manifest

Powershell is really testing my patience today... Ok, so I made a manifest to get my required assemblies. Now how do I properly import when I have a *.psm1 and *.psd1 file.

folder path: C:\\mypath\\blah\\blah\\Module\\Format-XML\\

files in folder: Format-XML.psd1, Format-XML.psm1

Import-Module -Name "C:\mypath\blah\blah\Module\Format-XML\Format-XML"

Then when I got to use my function in my module called from another script, for whatever reason, doesn't exist/work. What am I doing wrong?

[ERROR] VERB-NOUN: The term 'VERB-NOUN' is not recognized as the name of a

[ERROR] cmdlet, function, script file, or operable program. Check the spelling of the

[ERROR] name, or if a path was included, verify that the path is correct and try again.

In the *.psd1:

FunctionsToExport = '*'

In the *.psm1:

#I know... not required but I tried anyways... :(
Export-ModuleMember -Function '*'

So exactly following code need to be added to your psd1.

# Script module or binary module file associated with this manifest.
RootModule = 'nameOfYourModule.psm1'

Have a look at the module that's imported. You can do this this 2 ways:

After import:

$mod = Get-Module -Name Format-XML

During import:

$mod = Import-Module -Name "C:\mypath\blah\blah\Module\Format-XML\Format-XML" -PassThru

Then you can check $mod and look at the .ExportedCommands property. Is anything listed?

Also try removing the second Format-XML (I'm assuming that last component refers to the module itself and not the folder).

答:不要忘记设置你的根模块在清单... 叹息

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM