0

When I start a script with "Run with Powershell" its starting slow. First it is searching for avaiable modules and after this its asking for a Execution Policy Change. Is there a way to suspend them?

Thanks for the help!

guiwhatsthat
  • 2,349
  • 1
  • 12
  • 24

2 Answers2

0

Sure but understand the consequences

Set-ExecutionPolicy Unrestricted –Forc

M O'Connell
  • 487
  • 5
  • 18
  • Less [technical breakdown](http://jeffwouters.nl/index.php/2011/11/powershell-and-the-exectution-policies-explained/) – M O'Connell Sep 13 '16 at 07:49
  • 1
    This is verging on a [link-only answer](http://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-elsewhere-really-good-answers). Maybe summarize the consequences in your answer – Mathias R. Jessen Sep 13 '16 at 08:01
  • I know, that i can change the Execution Policy. By GPo the setting is RemoteSigned. But why is powershell asking me to change it when i run a script? – guiwhatsthat Sep 13 '16 at 08:07
0

Starting with version 3, Powershell does module autoloading, which you can disable by adding this line to your Powershell script (or profile):

$PSModuleAutoloadingPreference = “none”

Be careful, though, as this means that any cmdlet/function that's not part of the default modules Powershell loads at startup will not be available. As an indication, I launched (get-command).count both with and without that line: Module autoloading on: 1753 Module autoloading off: 213

If you need to load more modules, you can simply add Import-module instructions in your script.

As for the execution policy, you can also force it when launching powershell:

powershell -executionpolicy unrestricted <path to your script>

As was mentioned earlier, be careful with this parameter, as it will enable launching any Powershell script on your system. As long as you're in control of what scripts you're launching, there's nothing to be worried about.

Poorkenny
  • 1,246
  • 11
  • 16