powershellpowershell-module

Commandlets from a custom Module not being recognised


I have a custom Powershell module I have been working on for the past few days, I am now trying to integrate it into powershell as a module that always gets auto loaded.

My module is placed under the C:\Users\...\Documents\PowerShell\Modules , which is one of the places Powershell expects modules from. This is the structure for the module:

C:\Users\...\Documents\PowerShell\Modules\MetaData-System\MetaData-System.psm1
C:\Users\...\Documents\PowerShell\Modules\MetaData-System\MetaData-System.psd1

The MetaData-System.psd1 files contents are:

@{

ModuleVersion = '0.0.1'

GUID = '9e976eac-1010-4e0b-95e4-76c8bfc1ece1'

Author = '...'

CompanyName = 'Unknown'

Copyright = '(c) .... All rights reserved.'

FunctionsToExport = @( 'Set-Metadata', 'Clear-Metadata')

CmdletsToExport = @()

VariablesToExport = '*'

AliasesToExport = @()

PrivateData = @{

    PSData = @{

    }

}

}

The MetaData-System.psm1 files contents consists of two functions called Set-MetaData and Clear-MetaData. In Terminal running Get-Module -ListAvailable lists:

Directory: C:\Users\...\Documents\PowerShell\Modules  
  
ModuleType Version PreRelease Name PSEdition ExportedCommands  
---------- ------- ---------- ---- --------- ----------------  
Manifest 0.0.1 MetaData-System ... {Set-Metadata, Clear-Metadata}

But when I try to use one of the functions from the module by typing "Set-Met" no autocomplete occurs, neither do any parameters get suggested. If I write it all down such as:

Set-Metadata -path "C:\Users\...\Documents\test.txt" -Flags "Hello World

I get this error:

Set-Metadata: The term 'Set-Metadata' is not recognized as a name of a cmdlet, function, script file, or executable program.  
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

I have searched everywhere to see what I am doing wrong and out of ideas now.

I have taken the liberty to cross post this question on other forums as well.

Any help would be greatly appreciated!

EDIT: As suggested by @Abraham Zinala, I tried Get-Module:

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Manifest   0.0.1                 MetaData-System
Manifest   7.0.0.0               Microsoft.PowerShell.Management     {Add-Content, Clear-Content, Clear-Item, Clear-ItemProperty…}
Manifest   7.0.0.0               Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object…}
Script     2.1.0                 PSReadLine                          {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PSReadLineKeyHandler, Set-PSReadLineKeyHandler…}

No commands are present for the MetaData-System module.


Solution

  • Your module manifest is missing the following entry:

    RootModule = 'MetaData-System.psm1'
    

    This is necessary for the implementing script module file (*.psm1) to be discovered.

    In the absence of it, it is only the manifest file (.psd1) that is discovered, and the implementation of the exported commands is effectively missing.

    This is evidenced by your sample Get-Module output listing the ModuleType as Manifest rather than Script.