Passing a PSSession into a function and checking for Empty

Hi all,

So, I’ve got a function that calls a series of functions that all have remote sessions within them trying to parse repeatable steps out amongst them. End of the day there is really only a single server that most of these will remote to as part of their process in the larger script. I know with string values you can use an if to do something like

if([string]::isnullorempty) {do thing}

 

My question is this. Is there a way to do that with a PSSession. So I have a variable called $sqlsession. Trick is I don’t know how to check that variable and if there is a clever way of doing this. Mostly because if I mistype my admin execution password I get hit with a lockout by AD.

Don’t over engineer this.
Why not do this as background Jobs, then when they are done, just grab the results with receive job?

If all your function is targeting a single server, then you will hit with different issues. PowerShell remoting uses winrm and it has some default setting. One among them is maxconnections. If you are using same session, then maxshellperuser has to be checked.

As @postanote suggested, you could try using background jobs. But jobs can hit performance if they are many. In that case you can think about runspaces using PoshRSJob module.

btwn, if you could show a sample code for you scenario, it will be help full for us for further assistance.

Thanks for the responses. I’ll take a look at using background jobs. All of the aspects on these things run really quickly, 1-10 seconds and the overall tool is being built for dev/uat refreshes from the production environment backups.