I'm trying to start a background process with Start-Job in order to execute code while a modeless Winform shows on the primary process thread (showing the form and executing code on the same thread was causing the form to not show properly). I'm passing in a scriptblock using the -InitializationScript parameter that contains a lot of functions that the primary scriptblock (on the -ScriptBlock parameter) needs. Example:
Start-Job -InitializationScript $Globals -ScriptBlock $ScriptBlock -Name 'Main' | Wait-Job
My problem is that when the Job tries to begin, it immediately errors with the following:
[localhost] There is an error launching the background process. Error reported: The filename or extension is too long.
+ CategoryInfo : OpenError: (localhost:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : -2147467259,PSSessionStateBroken
Further testing revealed that this only occurs when the Initialization scriptblock is very large (as mine is). But I can't find any official documentation stating that there is a size limit for scriptblocks passed to Start-Job. Can anyone confirm that this is the case or offer any alternatives?
Thanks