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

10,509

Solution 1

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
)

Solution 2

When installing modules from a downloaded zip file (for example, when downloading AWS powershell tools as a zip file), this same error can also be caused if the Zip file was blocked as unsafe.

Unblocking the zip file before extracting modules seemed to fix this error for me.

Share:
10,509
reZach
Author by

reZach

Updated on June 05, 2022

Comments

  • reZach
    reZach almost 2 years

    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?