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
}

This function seems reasonable, right? Well, when it's called, there's no error, but absolutely nothing happens. Here's an example call.

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" }
}

Output:

Checking if pawshrp4001 exists and is awake ...
Failure!

The function call is completely skipped over. How?

patrickjp93
  • 399
  • 4
  • 20
  • One of the usual powershell gotchas. Your call to GetAWServer shouldn't have parentheses => GetAWServer $server $awsCreds. – David Brabant Oct 11 '16 at 07:01

1 Answers1

0

In PowerShell, parameter arguments are separated by whitespace, not commas.

The correct way of calling that function would be either:

GetAWSServer $server $awsCreds

or (using named parameters):

GetAWSServer -myServer $server -myCreds $AwsCreds
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206