Reputation: 743
I am trying to load PowerShell Script Module. Below is the step I am following
I have created 2 files under folder "C:\windows\system32\WindowsPowerShell\v1.0\Modules**PSModuleTest**"
PSModuleTest.psd1
@{
ModuleVersion = '1.0'
GUID = '7e8f93e6-5bde-4043-918e-322066c5340e'
Author = 'ravi'
CompanyName = 'Unknown'
Copyright = '(c) 2016 Ravi. All rights reserved.'
FunctionsToExport = '*'
CmdletsToExport = '*'
VariablesToExport = '*'
AliasesToExport = '*'
}
PSModuleTest.psm1
function ModuleTestFunction
{
Write-Host "Hello world!!!"
}
Once above two files are placed under correct folder I have tested whether the module path is included in $env:PSModulePath or not and its there. I also verified that I am not on older version of PowerShell by entering $host command.
When I executed Get-Module command, surprizingly i dont see my new module loaded. So I tried to load the module by entering below command and it did not worked.
Import-Module -Name PSModuleTest -Force -Verbose
See below image for all the command's output for more details.
Upvotes: 0
Views: 2227
Reputation: 4260
You can see from your screenshot above that after you've imported it PSModuleTest has no exported commands.
You need to declare PSModuleTest.psm1 in your module manifest file as long as you have a manifest available. e.g.
# Script module or binary module file associated with this manifest.
RootModule = 'PSModuleTest.psm1'
This is normally the first field in the manifest if you used New-ModuleManifest
to create it.
Your module won't be visible in a session until it has either been explicitly loaded or auto-loaded. It can only auto-load if commands can be discovered relatively easily (or the commands in the module are cached).
This command will show modules, included those which are not loaded:
Get-Module -ListAvailable
Upvotes: 1