単一のモジュールで、AWS API と対話するためのいくつかの powershell を作成しています。Get-CloudFormation
CloudFormation のステータスを返す1 つの関数を作成しました。別の関数 を作成しました。この関数はDelete-CloudFormation
、delete-CF API リクエストを発行した後、 my を使用して CloudFormation のステータスをポーリングするジョブを開始しようとGet-CloudFormation
します。
私は呼び出しますExport-ModuleMember
(Get-CloudFormation
しかし、そうではありません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を見つけましたが、で呼び出すStart-Job
と-InitializationScript { Get-CloudFormation }
ほぼ同じエラーが発生します。
Start-Job を呼び出す-InitializationScript { Import-Module ".\awsutils.psm1" }
と.
、プロファイルのドキュメント ディレクトリになります。変数をGet-Location
の外側にバインドして のStart-Job
ように呼び出しても-InitializationScript { Import-Module "$location\awsutils.psm1" }
。