【发布时间】:2012-03-12 19:59:00
【问题描述】:
我正在编写一些 powershell 以在单个模块中与 AWS API 对话。我编写了一个函数 Get-CloudFormation,它返回 CloudFormation 的状态。我编写了另一个函数 Delete-CloudFormation,它在触发 delete-CF API 请求后,尝试使用我的 Get-CloudFormation 启动一项轮询 CloudFormation 状态的作业。
我在Get-CloudFormation 上调用Export-ModuleMember(但不是Delete-CloudFormation;这是一个私有函数)。 Get-CloudFormation 在模块文件中的定义早于 Delete-CloudFormation。
我的Start-Job 电话(在Delete-CloudFormation 内)看起来像:
$job = Start-Job -Name "CloudFormationWaitForDeleteSuccess" -ScriptBlock {
$status = ""
$time = 0
while($status -ne "DELETE_COMPLETE") {
Write-Verbose ("Checking CloudFormation status")
$stack = Get-CloudFormation -accessKey $accessKey -secretKey $secretKey -stackName $stackName
$status = $stack.Status
Start-Sleep -seconds 10
$time += 10
}
Write-Host "CloudFormation delete-complete after $time seconds $stackName"
}
当Delete-CloudFormation 运行时,我得到一个异常:
The term 'Get-CloudFormation' 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.
+ CategoryInfo : ObjectNotFound: (Get-CloudFormation:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
为什么?我该如何解决?
我发现7152090 我认为是相似的,但是用-InitializationScript { Get-CloudFormation } 调用Start-Job 会产生大致相同的错误。
如果我用-InitializationScript { Import-Module ".\awsutils.psm1" } 调用Start-Job,那么. 是我个人资料的文档目录。即使我将一个变量绑定到Start-Job 之外的Get-Location 并像-InitializationScript { Import-Module "$location\awsutils.psm1" } 一样调用它。
【问题讨论】:
标签: powershell jobs powershell-2.0 powershell-jobs