Question

I am loading Powercli snapin in my script. If i execute a script first time in a session it takes more time. When i am executing another script which uses the same snapin ,it takes less time.[I measured the performance using Measure-Command cmdlet]

So i think whenever new session is created , it takes more time to execute the script.

In our case , as users will execute powershell by right clicking the file and run with powershell it will always run in new session. So every time they are facing slowness.

Why executing the powershell script first time in a session takes much time?

Is there any way to avoid this slowness? [I am using Powershell 2.0]

Was it helpful?

Solution

You're loading the snap-in. When you run your script the second time in the same session it is already loaded so Add-PSSnapIn returns quickly as it notices there is nothing to do.

If you want to always load the snap-in, yu can do so in your profile. Simply do

notepad $profile

in PowerShell and append the Add-PSSnapIn call.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top