Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, July 29, 2015 9:08 AM
Hi,
As a newbie, I wrote a short script to run it every time Windows (8.1) starts up. I put it under the "Startup Script" section in 'Group Policy Editor' and in its COMPUTER CONFIGURATION\WINDOWS SETTINGS\SCRIPTS address. The Windows is a live version running from USB Flash Drive; so, it is intended to be run in a variety of systems.
The problem is that in some systems it runs very late which is very critical to me; though, its execution time varies between less than a second and 2-3 seconds (using Measure-Command). I think the process of loading PowerShell modules is a bottleneck and I am looking a fast and affordable way to make that process drastically faster.
I checked also many links such as this "**http://blogs.msdn.com/b/powershell/archive/2008/09/02/speeding-up-powershell-startup-updating-update-gac-ps1.aspx?PageIndex=1#comments**", but no benefit I got. The script in that link could not be run as it showed some errors in it.
Any help is welcome?
All replies (7)
Wednesday, July 29, 2015 9:16 AM
Hi Sisili,
if speed is your primary concern, don't script it. Code it in C++.
On the scale you are thinking, all optimizations you can gain from PowerShell will be marginal compared to doing it this way (if you can do it in C++, which is probable).
Cheers,
Fred
There's no place like 127.0.0.1
Wednesday, July 29, 2015 10:22 AM
Load time is mostly a function of processor and memory.
How do you know it is module load that is slow? You have not provided enough info for anyone to be able to help with this.
\(ツ)_/
Wednesday, July 29, 2015 12:28 PM | 1 vote
There's not enough detail to tell for sure, but typically when modules are imported for a script there's only one or two cmdlets or functions in the module the script actually uses. If this is the case, you should be able to cut down on the load time by using the -cmdlet or -function parameters of Import-Module to only load the cmdlets or functions from the module that the script is actually going to use.
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Wednesday, July 29, 2015 12:45 PM
Ahh yes. Partially loading modules can help but one thing here that is more costly. If the script is run as a startup script then it will have to wait for the Net Framework to load. That is going to be last on a boot. The UI will be up and many other programs will be up before Net is available.
If you can run VBScript and WMI it would be somewhat faster as the WMI and shell are up sooner and both execute very fast on first load.
\(ツ)_/
Wednesday, July 29, 2015 12:54 PM
Also:
$PSModuleAutoLoadingPreference='None'
$PSModuleAutoLoadingPreference='ModuleQualified'
\(ツ)_/
Wednesday, July 29, 2015 1:03 PM
help Export-Console -full
\(ツ)_/
Saturday, August 1, 2015 7:09 AM
Hi jrv,
If loading process at startup is something like this ".Net Framework->Powershell Core->MyScript", you are right. My Windows UI is up and my script has not yet run. So, is it worthy to spend some time to use "$PSModuleAutoLoadingPreference='None' " technique to load modules manually in my little script? How could I speed up the above load process by changing, for instance, the 'powershell core' loading mechanism, because it is before the 'autoload' feature comes to act when executing powershell scripts?
Thanks