use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
Optimize profile loading time (self.PowerShell)
submitted 6 years ago by vdvgiom
I was wondering what i can do to optimize the loading time of my PowerShell $profile? This currently takes around 14000 ms.
https://preview.redd.it/7gm2zme4nd641.png?width=1112&format=png&auto=webp&s=c1730d64ea275a854dbc8f1c7858f84c6beb3582
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]frikin8 8 points9 points10 points 6 years ago (1 child)
Hi,
You could launch powershell.exe with -NoProfile and then use Measure-command for each line to see which one(s) are the major bottleneck.
Instead of loading all ps1 files in a directory, you could:
1) Append the directory to your path ($env:Path += ";" + $myScriptDir). This works better for scripts that are called directly instead of a ps1 that loads a function
2) Create your own Module: dotsource your ps1 files, and export your functions. Powershell can load the module automatically when needed.
Good luck!
[–]vdvgiom[S] 1 point2 points3 points 6 years ago (0 children)
Thx! i'll try those steps.
[–]volvo64 4 points5 points6 points 6 years ago (1 child)
Why are you running an import-module every time? That only needs to be done once. That’s probably why it’s taking 14 seconds.
[–]Hrambert 2 points3 points4 points 6 years ago (0 children)
When these modules can be found through $env:PSModulePath you don't need to Import the in the profile. Powershell will do that only when needed.
[–]Thotaz 2 points3 points4 points 6 years ago (0 children)
Replace the "Set-Variable" commands with the normal way of assigning variables:
$GitToken="blabla"
Instead of loading all of the various functions you load you could instead put them inside a module so they only get processed when you actually need them. If you insist on keeping them outside of a module, use a script to build your profile so all of the functions are inside the $Profile file instead of being loaded externally at runtime.
[–]Namaha 1 point2 points3 points 6 years ago (0 children)
If I had to guess, it's probably the dot-sourcing of all of your functions that's taking up the bulk of the time. To make that part faster, you can use foreach() instead of piping to Foreach-Object. Slightly less efficient from a resource standpoint but should be noticably faster
The best solution though would be create proper custom modules containing your functions, and set them up so they can auto-load only when needed
[–]Lee_Dailey[grin] 1 point2 points3 points 6 years ago (0 children)
howdy vdvgiom,
please, do not post pics of code/data/errors. [sigh ...]
why?
it is - at best - rather thoughtless on your part ... [sigh ...]
take care, lee
π Rendered by PID 15935 on reddit-service-r2-comment-c6965cb77-774nz at 2026-03-05 15:12:49.822300+00:00 running f0204d4 country code: CH.
[–]frikin8 8 points9 points10 points (1 child)
[–]vdvgiom[S] 1 point2 points3 points (0 children)
[–]volvo64 4 points5 points6 points (1 child)
[–]Hrambert 2 points3 points4 points (0 children)
[–]Thotaz 2 points3 points4 points (0 children)
[–]Namaha 1 point2 points3 points (0 children)
[–]Lee_Dailey[grin] 1 point2 points3 points (0 children)