Defining functions

I’m not sure if I’ve just misunderstood something but I’m trying to define some functions that I can then use in endpoints (or elsewhere)

I have it like this at the moment. Assuming that this is the correct order…

Function Get-Info1{
}
Function Get-Info2{
}

New-UDEndpointInitialization -Function @("Get-Info1", "Get-Info2")

$Endpoint1 = New-UDEndpoint -Schedule $Schedule5 -Endpoint {
    $Cache:GetInfo1 = Get-Info1
}
$Endpoint1 = New-UDEndpoint -Schedule $Schedule5 -Endpoint {
    $Cache:GetInfo2 = Get-Info2
}

The endpoint initialization needs to be added to the dashboard.

function F1 {}
function F2 {}
$EI = New-UDEndpointInitialization -Function F1, F2
$Dashboard = New-UDDashboard -EndpointInitialization $EI -etc

Thanks,
Tim Curwick

Alternatively, you could define the functions within a scriptblock stored as a cache-level variable, and invoke the scriptblock at the top of the endpoint. This gives you more flexibility as to when and where and how often you define the functions, and allows them to be defined only in the endpoints you specify.

$Cache:Functions = {
    function F1 { <#code#> }
    function F2 { <#code#> }
    }

$Endpoint1 = New-UDEndpoint -Endpoint {
    . $Cache:Functions
    $X = F1
     <#code#> 
    }

Thanks,
Tim Curwick

2 Likes