PowerShell模块未正确公开命令
我有一个奇怪的问题,因为我重新搭建了我的PowerShell模块 cfsdevops.psm1相当简单,只需自动导入PowerShell模块未正确公开命令,powershell,powershell-module,Powershell,Powershell Module,我有一个奇怪的问题,因为我重新搭建了我的PowerShell模块 cfsdevops.psm1相当简单,只需自动导入/private和/public中的所有.ps1文件即可 #Get public and private function definition files. $Public = @( Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -ErrorAction SilentlyContinue ) $Private = @( Get-C
/private
和/public
中的所有.ps1文件即可
#Get public and private function definition files.
$Public = @( Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -ErrorAction SilentlyContinue )
$Private = @( Get-ChildItem -Path $PSScriptRoot\Private\*.ps1 -ErrorAction SilentlyContinue )
#Dot source the files
Foreach($import in @($Public + $Private))
{
Try
{
. $import.fullname
}
Catch
{
Write-Error -Message "Failed to import function $($import.fullname): $_"
}
}
Export-ModuleMember -Function $Public.Basename
一旦我将所有文件发布到我的模块路径目录并尝试运行其中一个命令,我会收到一个错误,表明它不是有效的命令:
PS C:\> get-podconfig
get-podconfig : The term 'get-podconfig' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ get-podconfig
+ ~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (get-podconfig:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
然而,当我运行“Get Command-Module cfsdevops”时,它列出了所有可用的命令,并且在该会话中工作正常
PS C:\> Get-Command -Module cfsdevops
CommandType Name Version Source
----------- ---- ------- ------
Function add-deploymanifest 4.1.0 cfsdevops
Function add-podconfig 4.1.0 cfsdevops
Function add-tenant 4.1.0 cfsdevops
Function gen-podconfig 4.1.0 cfsdevops
Function get-aobcredential 4.1.0 cfsdevops
Function get-podconfig 4.1.0 cfsdevops
Function get-servertraffic 4.1.0 cfsdevops
Function new-deploymanifest 4.1.0 cfsdevops
Function publish-octopus 4.1.0 cfsdevops
Function publish-webconfig 4.1.0 cfsdevops
Function set-aobcredential 4.1.0 cfsdevops
Function set-octopusapikey 4.1.0 cfsdevops
您的
Get命令-Module cfsdevops
不显示Get podconfig
,但显示gen podconfig
。因此,错误消息完全有意义
检查脚本文件名和您的PowerShell模块清单(psd1文件)是否有打字错误。gen podconfig是一个打字错误吗?很奇怪,我上面的例子我指得很粗-实际函数没有回来。然而,从那时起,它奇迹般地发挥了作用。没有任何改变。