2016-10-11 4 views
0
#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 
} 

이 기능은 합리적인 것 같습니다. 맞습니까? 음, 호출 될 때 아무런 오류가 없지만 전혀 아무 일도 일어나지 않습니다. 다음은 예제 호출입니다.PowerShell : 함수 호출이 사라집니다?

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

하나. GetAWServer에 대한 호출에는 괄호 => GetAWServer $ server $ awsCreds가 없어야합니다. –

답변

0

PowerShell에서 매개 변수 인수는 쉼표가 아닌 공백으로 구분됩니다.

올바른 일 중 하나 것이라고 함수를 호출 방법 :

GetAWSServer $server $awsCreds 

또는 (명명 된 매개 변수를 사용하여) : 보통 PowerShell을 개는의

GetAWSServer -myServer $server -myCreds $AwsCreds