I am writing several powershell to talk with AWS API, in one module. I wrote one function, Get-CloudFormation , which returns the status of CloudFormation. I wrote another Delete-CloudFormation , which, after disabling the API request, delete-CF tries to run a task that checks the status of CloudFormation using Get-CloudFormation .
I call Export-ModuleMember on Get-CloudFormation (but not Delete-CloudFormation ; this is a private function). Get-CloudFormation defined earlier in the module file than Delete-CloudFormation .
My Start-Job call (inside Delete-CloudFormation ) looks like this:
$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" }
When Delete-CloudFormation , I get an exception:
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
Why? And how to fix it?
I found 7152090 , which, it seems to me, is similar, but calling Start-Job with -InitializationScript { Get-CloudFormation } gives about the same error.
If I call Start-Job with -InitializationScript { Import-Module ".\awsutils.psm1" } , then . is my document directory. Even if I bind the variable to Get-Location outside of Start-Job and name it as -InitializationScript { Import-Module "$location\awsutils.psm1" } .
Peter Mounce
source share