3

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.

  • 2
    Might sound like a silly question but, did you run a new PowerShell instance, or have you imported the module into your current session? Can you run `Get-Module` by itself and see if it shows in the returned output? Specifying `-ListAvailable` will list available modules instead of **loaded** modules, so without it, the command should output the current modules loaded in memory. – Abraham Zinala Aug 18 '22 at 15:25
  • 1
    @AbrahamZinala, not silly at all. I manually restarted terminal several times and did try the import-module command, still facing the same issue. I also downaloded a module called `PSWriteHTML` from Powershell gallery just to see its folder structure and its `.psd1` structure, they are identical to my folder structure and `.psd1` as well. – hellen_dorandt89 Aug 18 '22 at 15:35

1 Answers1

4

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.

mklement0
  • 382,024
  • 64
  • 607
  • 775
  • 1
    The guide I was following did not mention this key, Thanks allot for bringing my attention to the manifest page. All Commandlets and Parameters are there now. it feels so much better than I expected. So happy now :] – hellen_dorandt89 Aug 18 '22 at 16:01
  • Glad to hear it, @hellen_dorandt89; my pleasure. – mklement0 Aug 18 '22 at 16:02