r/PowerShell • • Apr 06 '21

Optimizing your $Profile

https://devblogs.microsoft.com/powershell/optimizing-your-profile/
119 Upvotes

24 comments sorted by

View all comments

2

u/motsanciens Apr 08 '21 edited Apr 08 '21

I got a lot of mileage out of this post, not the least of which is the Measure-Script tool, which is pretty sweet.

I couldn't help but try to re-invent the wheel to try to improve on the idea. I'm not sure I came up with anything novel, but there could be some things in here that spark some ideas for anyone who comes along.... https://pastebin.com/5iBXXS9r

One thing I did that may not be immediately obvious is include a file in the gist called "version" that just contains, you guessed it, the version. To me, it made sense to make a call for the version instead of pulling the whole profile script and then pattern matching to get the version. You end up with two http calls, but it's only when there's a real need to update.

I also included a way to turn the profile updater to manual or auto, and I had a lot of fun (yes, let's call it that) with scriptblocks along this journey.

Edit: After spamming [Enter] at the prompt and locking up my system, I added a limit of 5 background jobs at a time.