Connecting to VMware Vcenter in nested script

We have an automation thing going on, or rather 15-20 of them. Most of them starts with connecting to several VMware VCenters. I want to avoid duplicating that code in evry automation, thus putting it in a separate script and then call that from the automations.
I have used “Invoke-PSUScript -Script ‘Script1.ps1’ | Wait-PSUJob” and it works as expected except for that the connections are made in the session of that script (Script1) and not available after the script ends.

So how would I go about to either get state of objects (ie Vcenter connections) to another script, or better, get the invoked script to run in the same contect/session as the script that is calling it?

Solved. Was as easy as just adding the script with “.<path and name to Script1.ps1>”.

I can recommend you to write against VMware’s restAPIs don’t use powercli

We’ve been using PowerCLI for a nnumber of years and only issue thus far is that PowerCLI error handling can be a bit tricky, but not really an issue.
So what would motivate going the Rest way instead in your opinion?

You will get issues when using PSU and different run spaces etc

Can you give an example of such an issue?
We previously used another automation platform, where we ran each automation in separate PS sessions. The only issue with that (which we solved) was when we really wanted to share information between the sessions, which luckily didn’t happen often.