Need help improving performance please ...

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 7 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
skalizar
Posts: 18
Last visit: Wed Nov 22, 2023 12:43 pm

Re: Need help improving performance please ...

Post by skalizar »

grathal wrote:...
My only worry is that using the Foreach-Object is a *lot* slower compared to the Where-Object.
I suppose that's possible, but it doesn't make much sense. You can measure time on various operations to confirm the individual operation is the culprit. Just remember to start with a fresh session for each test so caching doesn't come into play, and repeat a few times in case background jobs are affecting the results.

https://technet.microsoft.com/en-us/lib ... 76899.aspx

Also, foreach and ForEach-Object are 2 different things. If Where-Object is indeed more than twice as fast, then just do 2 of them with opposing conditions.

$ValidData = $MasterFileData | Where-Object { -not ([string]::IsNullOrWhiteSpace($_.Email)) }
$InvalidData = $MasterFileData | Where-Object {([string]::IsNullOrWhiteSpace($_.Email)) }
User avatar
grathal
Posts: 98
Last visit: Tue Nov 27, 2018 4:16 am

Re: Need help improving performance please ...

Post by grathal »

Thanks for the tips.

Would you believe what I've ended up doing is using Compare-Object to report the difference between $MasterFileData and the $ValidData subset with the -PassThru parameter.
I'm piping that into Out-GridView, filtering where the sideIndicator is "<=".

I'm sure there's a better way but it just works. :)
This topic is 7 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked