bin/Invoke-NewEndpoint.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<#
.DESCRIPTION
 This Script will Execute a specified task, and submit any needed subtasks.
.PARAMETER SourceAvailableRoutesFile
 A Rest PropertyFilePath is required.
.PARAMETER Port
 A Rest PropertyFilePath is required.
.EXAMPLE
 Start-Process -WindowStyle Normal powershell.exe -ArgumentList "-file Invoke-NewEndpoint.ps1", "-SourceAvailableRoutesFile $SourceAvailableRoutesFile -Port $Port"
.NOTES
 This will start a new PembrokePS Endpoint.
#>

param(
    [Parameter(Mandatory=$true)][String]$SourceAvailableRoutesFile,
    [Parameter(Mandatory=$true)][Int]$Port
)
# Import required Modules
Import-Module -Name PowerLumber,RestPS -Force
try 
{
    if (Test-Path -Path $SourceAvailableRoutesFile)
    {
        $Host.UI.RawUI.WindowTitle = "PembrokePS Endpoint Port:$Port"
        Start-RestPSListener -Port $Port -RoutesFilePath $SourceAvailableRoutesFile
    }
    else 
    {
        Throw "Invoke-NewEndpoint: Routes File: $SourceAvailableRoutesFile does not exist."
    }
}
catch
{
    $ErrorMessage = $_.Exception.Message
    $FailedItem = $_.Exception.ItemName        
    Throw "Invoke-NewEndpoint: $ErrorMessage $FailedItem"
}