Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The '' command was found in the module '', but the module could not be loaded

No other questions seem to answer my question, so I am posting it here. I am exporting functions from .psm1 files. My structure is this

Modules (folder)
    CompanyName (folder)
        SQL (folder)
            SQL.psm1

My result of Get-Module -Listavailable returns the file containing my commands. (It is clear that my path is correct, otherwise this call would not return the functions I export in SQL.psm1)

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     0.0        SQL                                 {Import-BCPFile, Export-BCPFile}

However, I get an error trying to run the function, Import-BCPFile : The 'Import-BCPFile' command was found in the module 'SQL', but the module could not be loaded. For more information, run 'Import-Module SQL'.

I run Import-Module SQL and get another error, Import-Module : The specified module 'SQL' was not loaded because no valid module file was found in any module directory.

Do you have any ideas why I can't call my function?

like image 254
reZach Avatar asked Oct 22 '25 17:10

reZach


1 Answers

If you were stuck like me, try importing the module like so,

Import-Module "C:\Program Files\WindowsPowerShell\Modules\Company\SQL"

Importing the module will return any syntax errors in your module. I ended up missing a comma in my parameter list. Fixing this allowed me to run Import-BCPFile in my powershell window!!

[CmdletBinding()]
Param(
    [Parameter(Mandatory=$True)]
    [string]$BCPFile,
    [Parameter(Mandatory=$True)]
    [string]$Database,
    [Parameter(Mandatory=$True)]
    [string]$TableToImport,
    [Parameter(Mandatory=$True)]
    [string]$SQLServer = "." # <-- missing a comma!

    [switch]$Truncate = $False
)
like image 153
reZach Avatar answered Oct 24 '25 07:10

reZach