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

34

u/Thotaz Apr 06 '21

I wish PS was faster to start in general. Even without any profiles the first launch after a fresh boot is pretty slow regardless of how fast your PC is. On slower/busier PCs it can easily take several seconds and it makes me pick cmd over PS for simple tasks like viewing the IP address or launching a program from a folder with special arguments.

4

u/justinwgrote Apr 07 '21

Have you used Powershell 7? Significant improvements were made to the boot time.

2

u/jantari Apr 07 '21

While that's true, I still wish startup was at least twice as fast even in v7

2

u/Thotaz Apr 07 '21

Yes and it's still worse than CMD.

1

u/HeKis4 Apr 07 '21

True. What really kills me is the time it takes for the first tab-completion of a session if you're tab-completing something from a module, like Get-ADUser -Prop *tab*. I could have typed the LDAP query faster than it takes to complete lol.

I think the console basically tries to parse your entire $PsModulePath when you do that, which takes ages especially on HDDs (don't ask me why I'm still using an HDD as a system drive in 2021). This is something that could be optimized a lot, I'm not sure I need my VMWare module ready to go if I'm doing AD work.

0

u/rmbolger Apr 07 '21

I mean, tab completing something from a module means it needs to actually import that module before it can know what to tab complete. And the AD module in particular is rather glacial on initial import. I'd guess it's primarily because it tries to setup the AD:\ drive connection to your default domain and it's even slower if you're on a non-domain joined machine.

0

u/Thotaz Apr 07 '21

The slow tab completion in this situation is because it has to import the module to figure out what parameters are available for the command. If you import the AD module in your $Profile you won't see this happen but this will of course make the initial start up slower.

-5

u/Where_Do_I_Fit_In Apr 07 '21

The starting speed of PowerShell and cmd side by side is pretty noticable (especially with a powerful PC). I don't really see a compelling reason to start PowerShell other than using cmdlets/scripting. cmd does the job and starts faster.

7

u/da_chicken Apr 07 '21

You just start Powershell and leave it open. You should close it when you need to reset the environment. If you don't know when you need to do that, you probably don't need to close it at all.

Besides, once you get used to Windows Terminal, you just don't think about opening a new tab.

2

u/elevul Apr 07 '21

Eh, no windows terminal on servers

1

u/[deleted] Apr 07 '21

[removed] — view removed comment

0

u/jantari Apr 07 '21

That's a preview release only currently. Also not sure whether it will work on Server Core or just Desktop. If it requires the desktop then it's useless

1

u/Thotaz Apr 07 '21

There's no way it'll support core. Core doesn't have all of the modern UWP/XAML components that it uses.

0

u/Where_Do_I_Fit_In Apr 07 '21

You just start Powershell and leave it open.

I tend to open a new shell (cmd/bash/ps) in a directory by right clicking in File Explorer, so this doesn't really work for me personally.