#Calls to this function magically disappear
Function GetAWSServer([string]$myServer, [Amazon.Runtime.SessionAWSCredentials]$myCreds)
{
Write-Output "GetAWSServer"
$appFilter = '*'+$myServer+'*'
$filter = New-Object Amazon.EC2.Model.Filter
$filter.Name = 'tag:Name'
$filter.Value = $appFilter
Write-Output "Filter: " $filter
try
{
$myInstance = (Get-EC2Instance -Credential $myCreds -Region ap-southeast-2 -Filter $filter) | Select -ExpandProperty Instances
} catch { $error[0] }
return $myInstance
}
这个功能看起来合情合理吧?好吧,当它被调用时,没有错误,但绝对没有任何反应。这是一个示例电话。
Write-Output "Checking if $server exists and is awake ..."
##### FIXME: Seriously, wtf?! Program doesn't seem to access the function
$instance
try
{
$instance = GetAWSServer($server, $awsCreds)
} catch {$error[0]}
$wasAwake = $true
if(-Not $instance.InstanceId)
{
Write-Output "Failure!"
$jobStatus = "Failure"
$jobOutput = "Server $server does not exist in the AWS workspace.`n `n"
continue
} else
{
#$wasAwake = WaitForAWSServer($instance, $awsCreds)
if( -Not $wasAwake ) { Write-Output $i.ServerInstalled + " was woken up" }
}
输出:
Checking if pawshrp4001 exists and is awake ...
Failure!
完全跳过函数调用。怎么样?
答案 0 :(得分:0)
在PowerShell中,参数参数由空格分隔,而不是逗号。
调用该函数的正确方法是:
GetAWSServer $server $awsCreds
或(使用命名参数):
GetAWSServer -myServer $server -myCreds $AwsCreds