Private/Invoke-EdenLocalCommand.ps1

function Invoke-EdenLocalCommand
{
    <#
    .SYNOPSIS
        Calls the script file in the Eden folder.
    .DESCRIPTION
        Used to transfer control to the local Eden script. Passes in the
        Settings object, Logging Prefix and any additional arguments provided
        to the script.
    .EXAMPLE
        PS> Invoke-EdenLocalCommand "SourceControl/Install-ServiceSourceControlTools" $settings $loggingPrefix
        Calls the Install-ServiceSourceControlTools script file in the
        './Eden/SourceControl' folder. The $settings object and $loggingPrefix
        will be passed to the script.
    .INPUTS
        None
    .OUTPUTS
        Returns the output of the script that is referenced.
    #>

    [CmdletBinding()]
    param(
        [String] $EdenCommand,
        $Settings,
        [String] $LoggingPrefix,
        [Hashtable] $AdditionalArgs
    )

    $edenCommandFile = "./Eden/$EdenCommand.ps1"

    try {
        if (!(Test-Path $edenCommandFile)) {
            throw "Could not find the file '$edenCommandFile' to execute the Eden command. Please add the file to the Eden folder."
        } else {
            # Write-Verbose "Calling $edenCommandFile"
            if ($Settings) {
                if ($AdditionalArgs) {
                    & $edenCommandFile -Settings $Settings -LoggingPrefix $LoggingPrefix @AdditionalArgs
                } else {
                    & $edenCommandFile -Settings $Settings -LoggingPrefix $LoggingPrefix
                }
            } elseif ($AdditionalArgs) {
                & $edenCommandFile -LoggingPrefix $LoggingPrefix @AdditionalArgs
            } else {
                & $edenCommandFile -LoggingPrefix $LoggingPrefix
            }
        }
    }
    catch {
        Write-EdenError "Error invoking the EdenCommand using file: '$edenCommandFile'" $LoggingPrefix
        Write-EdenError "Error Message: '$($_.Exception.Message)'" $LoggingPrefix
        if ($VerbosePreference -eq "Continue") {
            Write-Verbose $_.Exception
            Write-Verbose $_.ScriptStackTrace
        }
        throw
    }

}