- This topic has 1 reply, 2 voices, and was last updated 1 month, 1 week ago by
October 21, 2020 at 1:46 am #264836ParticipantTopics: 1Replies: 0Points: 7Rank: Member
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.
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).
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 …PowerShell1Start-Process -Filepath "$PSExec" -ArgumentList "\\$Server -h -d $RmtFldr2\test-exec.ps1"
But that isn’t working as I’d hoped.
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.
- This topic was modified 1 month, 1 week ago by kvprasoon. Reason: code formatting
October 21, 2020 at 2:08 am #264842Senior ModeratorTopics: 9Replies: 1420Points: 5,280Rank: Community MVP
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.
- You must be logged in to reply to this topic.