If the script you invoke on the guest is going off for a longer time, you might loose the connection due to a timeout.
A solution would be to let the script inside the guest OS send something back on a regular schedule.
In any case, I would prefer to start scripts, that take quite long to complete, with the RunAsync switch on the Invoke-VMScript cmdlet.
Start them and then go back regulalry to check if they are finsihed.
The downside, your script that runs inside the guest will have to set a flag when complete and store it's results somewhere to be retrieved.
And you will have to write a managing script that to polls regularly to check if the guest scripts are ready, and eventually retrieve the information. That makes it all a bit more complex on the management side.
Your choice