My issue is that variables set in one API call don’t persist in other calls even though a persistent runspace environment is used
It’s possible I don’t quite understand how persistent runspaces are supposed to work but I feel that I have things set up correctly, please let me know what I’m doing wrong here
Persistent runspaces will persist variables but PSU is still using a runspace pool. You’re likely hitting two separate runspaces. You will want to use the cache if you want to persist information across runspaces.
Hey @ScalbyLausisJim , you can also use a global variable to persist between APIs. The persistent Runspaces switch needs to be enabled in the environment.
Hi Adam
Thanks for the advice, that works to an extent, but I am having trouble properly deserializing the output of Get-PSUCache (am working with custom classes that contain other custom classes)
Are the PSUCache commands simply wrappers around Import/Export-CliXml cmdlets? Or is there anything extra going on behind the scenes? I have written a method to deserialize the cached objects which works correctly when dealing with the output of Import-CliXml but not with Get-PSUCache
I am tempted to use Export-CliXml directly instead of the PSUCache commands, unless there is some reason not to? Or alternatively use global variables as suggested above
I will note that I didn’t need to set up a persistent environment or set an API environment for the variables in the $cache scope to persist, not sure if this is intended