Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remoting question #62

Open
Stephanevg opened this issue Jun 22, 2020 · 1 comment
Open

Remoting question #62

Stephanevg opened this issue Jun 22, 2020 · 1 comment

Comments

@Stephanevg
Copy link

Hi @PaulHigin

I was wondering how this module could help me reduce time of fetching data over the network using Invoke-Command -ComputerName

Is that something that this module could do? would you have an example to share?

@PaulHigin
Copy link
Owner

Invoke-Command already supports fan-out scenarios, so in this case you don't need to use ThreadJob.

$resultsJob = Invoke-Command -Cn @('computer1','computer2','computer3',...) -FilePath .\GatherData.ps1 -ThrottleLimit 25 -AsJob

But if you were just copying files from network shares, or downloading from REST APIs, then because of the slowness of the connection, ThreadJob should speed things up quite a bit.

$destPath = 'c:\DestFolder'
$listOfSourcePaths = 'filePath1','filePath2',...
$listOfSourcePaths | Foreach-Object {
    Start-ThreadJob {
        Copy-Item -Path $using:_ -Dest $using:destPath -Recurse -PassThru -Force
    } -ThrottleLimit 25
} | Wait-Job | Receive-Job

If you are using PowerShell 7+, you can also use the new Foreach-Object -Parallel feature, which is simpler.

$destPath = 'c:\DestFolder'
$listOfSourcePaths = 'filePath1','filePath2',...
$listOfSourcePaths | ForEach-Object -Parallel {
    Copy-Item -Path $_ -Dest $using:destPath -Recurse -PassThru -Force
} -ThrottleLimit 25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants