Skip to content

Migrate scripts from ProcessRunner 1.x to 2.x

This article will help you migrate your scripts from 1.x to 2.x of Easit ProcessRunner.

Introduction

When executing the PowerShell script, EPR did this by adding the exported request from Easit GO as a JSON-string and appending it as an argument to the cmdLine runner. This would look something similar to this if running a script from the console.

1
    PS C:\Users\administrator> C:\Program Files\PowerShell\7\pwsh.exe -File [scriptfile.ps1] [requestbody]

In addition to the requestbody being sent as an argument, a base64 encoded string of the requestbody was sent via the stdin stream.

Scripts before 2.x

As a part of the "Best practices" guide, the following was recommended to add to all scripts.

1
2
3
4
5
6
7
    [CmdletBinding()]
    param(
        [Parameter(Mandatory,Position=0)]
        [string]$StringInput,
        [Parameter(Mandatory,Position=1)]
        [string]$Base64StringFromStdIn
    )

And to access the exported item from Easit GO we recommended the following approach.

1
2
3
4
5
6
7
    try {
        Write-CustomLog -Message "Converting Base64StringFromStdIn"
        $easitGOItem = Convert-EasitGOExportString -InputString $Base64StringFromStdIn
    } catch {
        Write-CustomLog -Message "$($_.Exception)" -Level ERROR
        return
    }

OR you could have used this approach

1
2
3
4
5
6
7
    try {
        Write-CustomLog -Message "Converting StringInput"
        $easitGOItem = $StringInput | ConvertFrom-Json
    } catch {
        Write-CustomLog -Message "$($_.Exception)" -Level ERROR
        return
    }

Scripts from 2.x and forward

We removed appending the exported request as an argument to the cmdLine runner and instead ONLY pass on the request body through the stdin stream. This change is a breaking change and for your scripts work you will need to update the parameter block to look like this.

1
2
3
4
5
    [CmdletBinding()]
    param(
        [Parameter(Mandatory,Position=0)]
        [string]$Base64StringFromStdIn
    )

You can still use the Convert-EasitGOExportString command to access exported item but you cannot use the $Base64StringFromStdIn | ConvertFrom-Json approach. Instead you could use this.

1
2
3
4
5
6
7
    try {
        $byteArray = [System.Convert]::FromBase64String($Base64StringFromStdIn)
        $utf8String = [System.Text.Encoding]::UTF8.GetString($byteArray)
        $easitObject = $utf8String | ConvertFrom-Json
    } catch {
        throw
    }