似乎没有其他问题可以回答我的问题,所以我将其张贴在这里。我正在从 .psm1 文件中导出函数。我的结构是这样的
Modules (folder)
CompanyName (folder)
SQL (folder)
SQL.psm1
Get-Module -Listavailable
的结果返回包含我的命令的文件。 (很明显我的路径是正确的,否则这个调用不会返回我在SQL.psm1中导出的函数)
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 0.0 SQL {Import-BCPFile, Export-BCPFile}
但是,我在尝试运行该函数时遇到错误, Import-BCPFile:在模块“SQL”中找到“Import-BCPFile”命令,但无法加载该模块。为了 更多信息,请运行“Import-Module SQL”。
我运行 Import-Module SQL
并得到另一个错误,
Import-Module:未加载指定的模块“SQL”,因为在任何模块中均未找到有效的模块文件
目录。
你知道为什么我不能调用我的函数吗?
最佳答案
如果你像我一样被卡住,尝试像这样导入模块,
导入模块“C:\Program Files\WindowsPowerShell\Modules\Company\SQL”
导入模块将返回模块中的任何语法错误。我最终在参数列表中遗漏了一个逗号。修复此问题后,我可以在我的 powershell 窗口中运行 Import-BCPFile
!!
[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
)
关于sql-server - 在模块 '' 中找到 '' 命令,但无法加载该模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48430075/