easitab / EPR.GlobalFunctions

Provide functions to be used in script executed by EasitProcessRunner
https://docs.easitgo.com/techspace/epr/globalfunctions/
Apache License 2.0
1 stars 0 forks source link

Add global variables for result object #65

Open easitanth opened 3 months ago

easitanth commented 3 months ago

We should provide a easy way to return a "result object" back to Easit GO when a scripts completes.

A suggestion is to create a PSCustomObject in 'Set-EPREnvironment' and add it as a global variable, for example 'eprResult'.

$eprResult = [PSCustomObject]@{
    eprErrorMessage = $null
    eprReturnMessage = $null
    eprReturnCode = 0
}
New-Variable -Name "eprResult" -Scope 'Global' -Value

Usage:

begin {
    Set-EPREnvironment
}
process {
    try {
        $fileContent = Get-Content -Path "$PSScriptRoot\myfile.txt" -Raw
    } catch {
        $eprResult.eprReturnMessage = "Unable to get content from file"
        $eprResult.eprErrorMessage = $_.Exception
        $eprResult.eprReturnCode= 1
    }
}
end {
    Send-ToEasitGO -Url 'urltoEasitGO' -Apikey 'myApikey' -ImportHandlerIdentifier 'resultFromEPR' -Item $eprResult
}