Group-object powershell memory issue

Hi All,

I have been using the following for sometime, however the logs I need to scan have grown immensely and it will no longer complete. Powershell will use around 4GiB and process endlessly. Logs are roughly 3.6 GB in total, select-string would hit on 90% of the lines. Ideas to optimize this would be greatly appreciated

$regex = “\DisplayName.*”
select-string -Path .\displayname.log -Pattern $regex -AllMatches | % { $.Matches } | % { $.Value } | Group-Object -Verbose -noelement | select name, count | sort-object count -Descending > displayname.Counts.log

Linux works without any issues, and much quicker performance. However this is not ideal for my automation.

perl -lne 'print $1 if /DisplayName(.)/’ displayname.log | sort | uniq -c | sort -nr >> displayname.Counts.log