Sharing data with Trigger scripts

Looking for some ideas on how to share data between jobs and triggers.

Currently I have one script that handles all of our triggers, I’ve found that using PSScriptInfo for some additional metadata and dumping job output via Get-PSUJobOutput seems to work okay for what I’m using it for right now.

Our trigger script is mainly responsible for creating tickets in our ITSM system if some of the jobs fail, but I am working on a job that will need more flexibility, and I still want one trigger script to be responsible for each, so currently I’m thinking that putting an object on the pipeline that the trigger script can pick up and use is the best scenario for my use-case.

Are some of you doing a similar thing, and is there something more rigid (built-in maybe?) that can be used in place of just putting objects in the job’s pipeline?

Product: PowerShell Universal
Version: 3.6.3

The only other way I can think of providing data to the trigger is through the cache.

Set-PSUCache -Key ($UAJob.Id) -Value $MyObject

Then in the trigger script, you could retrieve that data.

$MyObject = Get-PSUCache -Key $Job.Id
1 Like

So I played around with this idea, but ultimately I stumbled upon a cool little trick I didn’t know about.

The InformationStream in Powershell can be tagged using Write-Information like this:

[PSCustomObject]@{
    ButThisIsTheCustomPsObjectIWant = $true
} | Write-Information -Tags "DesiredData" -InformationAction Continue -InformationVariable iv

$iv

Using this I can filter from the Job Pipeline on Deserialized.System.Management.Automation.InformationRecord and then the Tag (In case something else wrote to the information stream) like this:

$o | Where-Object { $PSItem.PSObject.Typenames -contains 'Deserialized.System.Management.Automation.InformationRecord' } | Where-Object { $PSItem.Tags -Contains 'DesiredData' }

End Result in PSU with a test-script and various forms of output, and the corresponding object in the Trigger script

Now I just have to build this in production :slight_smile:

1 Like