I have this script that is getting a list of policies in the domain. This isn’t complex in any way. I’m running this within VS Code using PS 7.3.9, PS terminal 5.1, and PS Terminal 7.3.9. Here’s the line I’m running (with all the variations I’ve tried):
Get-GPO -All
Get-GPO -All -Domain “DOMAIN”
Get-GPO -All -Domain “DOMAIN” | Where-Object{$.DisplayName -NotLike “-lx-” -AND $.DisplayName -NotLike “*-lx”} | Select DisplayName, @{Name=“GUID”;Expression={$_.ID}} | sort DisplayName
Also, it doesn’t matter if I run it with the -domain flag or not, it takes 6 minutes to return the results if I run the script from within VS Code. If I run that same command, from the same system using either PS terminal, the results are returned in about 2 seconds.
I originally though maybe this was not really taking a long time to return the results and it was getting stuck somewhere else in the script. However, when I step through the code it hits the line to get the policies, it stops and sits for 6 minutes then moves on to return the results.
Anyone have any ideas on how to speed this up?