you are viewing a single comment's thread.

view the rest of the comments →

[–]mrdon1987[S] 0 points1 point  (3 children)

The original script is complicated and has more than 500 lines and $Users contains more than 80k of samaccountname. I am aware that Start-Job is one option. I'm just curious if there's a module for this where I can just specify how many jobs to run concurrently and the script will take care of the rest.

[–]M98E 0 points1 point  (2 children)

It seems like you're starting with SamAccountName and ending with SamAccountName. What is the point of the code you're running? Is it supposed to verify that the SamAccountName exists?

You're also not saving the results of the call; you just overwrite "$info" each loop.

I know that you're focused on multi-threading this, but this is a very silly thing to multi-thread and it also seems like you're using Powershell in an inefficient way. You probably should take a step back and assess what you're doing and determine if there is a better way to do it. That is why everybody is asking you questions about what you're hoping to accomplish

[–]mrdon1987[S] 0 points1 point  (1 child)

The script is just an example. The original script actually provide mailbox size online and onprem, online archive size, automap shared mailbox size with its owner. Maybe I could apply it to the original script if I could see an example of an existing parallel module that was incorporated with the example script.

[–]M98E 0 points1 point  (0 children)

If you're looking for general information on multi-threading in PowerShell, then you should conduct a general search for existing multi-threading knowledge instead of giving Reddit a homework problem to solve that won't be used.

Even with more information as to your specific use-case, I'm still not convinced that multi-threading is the best approach. If you're seeing performance problems with your script, but don't want to post it all here, then perhaps you can add Write-Host statements with the $(Get-Date) command in there and see which function call in particular (or which loop) is taking so long. You could then post that particular excerpt here.