- August 24, 2016 at 5:49 pm #51771
To leverage on parallelism, I am using Invoke-Command -File abc.ps1 to ship several 'Get-' functions to remote computers that run them locally, and then the output is shipped back (deserialized objects are ok).
Now, I would like to execute the individual functions locally from my computer. By doing this, I am looking at a foreach loop and/or using -ComputerName in the 'Get-' cmdlets which breaks the parallelism and slows down processing time.
Any suggestions to how I might accomplish this? Jobs?
AaronAugust 24, 2016 at 6:30 pm #51776
Hi Aaron, can you post a code sample of what you're attempting so I can understand the question a bit better?August 24, 2016 at 6:55 pm #51785
This is my current approach:
$RemoteSession = New-PSSession -ComputerName comp1,comp2,comp3,comp4,comp5 -Credential $Credential # functions.ps1 contains functions like Get-Services, Get-Process, # Get-CustomFunction1, Get-CustomFunction2, etc. that execute # locally on the remote computer. Output is exported to a local # path of the remote computer (D:\share). Invoke-Command -Session $RemoteSession -FilePath X:\Scripts\functions.ps1 # Run Import-CliXML manually to output results to console of local computer. Import-CliXML \\RemoteComputer\share\abc.xml
Rather than using "Invoke-Command -FilePath functions.ps1" for local execution on remote computers, the functions would have to be declared on my local session, which requires the use of -ComputerName or -CimSession on those cmdlets/functions, and only one remote computer can be processed at a time. The "one-at-a-time" is what I am trying to circumvent, if possible.
Hope this makes things clearer.
AaronAugust 24, 2016 at 7:36 pm #51788
I believe that the only way to avoid this would be through the use of PowerShell jobs. Unless some of these commands are extremely long running though, I'm not sure how much of a speed benefit you'll see versus the pain of implementation. Something like the code below should work. I'm just getting started with Jobs myself, so there may be a better way to do this, but this should work.
You must be logged in to reply to this topic.