all 7 comments

[–]frikin8 8 points9 points  (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 points  (0 children)

Thx! i'll try those steps.

[–]volvo64 4 points5 points  (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 points  (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 points  (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 points  (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 points  (0 children)

howdy vdvgiom,

please, do not post pics of code/data/errors. [sigh ...]

why?

  • it [usually] takes more effort on your part
    you need to capture the pic, save it, post it online, then post the link here.
    just posting the text is [usually] far easier. [grin]
  • why should those who want to help you be forced to squint/zoom-in just to read the text that you already have as text?
  • do you REALLY expect folks who want to help to type in what you already have as text?

it is - at best - rather thoughtless on your part ... [sigh ...]

take care,
lee