【发布时间】:2018-06-12 17:36:06
【问题描述】:
自从我重新搭建了 PowerShell 模块后,我遇到了一个奇怪的问题。
cfsdevops.psm1 相当简单,只需自动导入/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
【问题讨论】:
-
“gen-podconfig”是错字吗?
标签: powershell powershell-module