Remote PowerShell Execution Query

Hello All,
Am new to the forum & has been ages since I last wrote a script for any platform, but have been tasked with one in PowerShell recently.

In brief:
Running from Server-A (running PS 4.0), I have a listing of server names (700-800) to upload packages to and then execute a PS1 script (from the uploaded packages) on the remote server (Server-X).

Problem #1:
How best should I execute the remote .ps1 script (on Server-X) and can this be done in a Unix style background mode ‘&’?
The remote .ps1 script may take only a few minutes on some servers and take hours on others - hence seeking for a background mode capability.

I was this morning attempting to use …

Start-Process -Filepath "$PSExec" -ArgumentList "\\$Server -h -d $RmtFldr2\test-exec.ps1"

But that isn’t working as I’d hoped.

Problem #2:
Am finding that some of the servers I need to connect to are running PS 2.0 - how best to write the scripts to accommodate varying/unknown PS versions?

Any assistance would be really appreciated.


Background jobs are created using Start-Job cmdlet in PowerShell and remote executions are triggered using Invoke-Command cmdlet.

You can use Invoke-Command to trigger the script and no need to use Start-Job as remote executions are always ran in background in the remote node.
Invoke-Command do have -ComputerName parameter which can take array of computers with a default throttle limit of 32. So when array of computer is passed, the node
from where the trigger happens will have execution happening in threads per computer. Invoke-Command has a parameter -Disconnected, but this can be used only from PS v4 I think.