6

I have a Windows 2008 R2 server with Powershell V4.0

I got a very simple script test.ps1 with this content :

Write-host "Hello world!"

I call this script from a powershell prompt like this :

measure-command { powershell.exe -file .\test.ps1 }

I got extremely high value as you can see :

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 7
Milliseconds      : 992
Ticks             : 79922815
TotalDays         : 9,25032581018519E-05
TotalHours        : 0,00222007819444444
TotalMinutes      : 0,133204691666667
TotalSeconds      : 7,9922815
TotalMilliseconds : 7992,2815

Or

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 4
Milliseconds      : 655
Ticks             : 46556579
TotalDays         : 5,38849293981481E-05
TotalHours        : 0,00129323830555556
TotalMinutes      : 0,0775942983333333
TotalSeconds      : 4,6556579
TotalMilliseconds : 4655,6579

And it taking my cpu at 50%. Why it's too long ? I tried with -noprofile but it's same.

Thanks for your help.

0

1 Answer 1

7

Powershell loads and JIT compiles tons, and tons, and tons of stuff. This takes a lot of excessive CPU cycles and disk I/O.

Try using ngen.exe (Native Image Generator) to precompile the assemblies that Powershell loads during startup. Just might improve your startup time.

$FrameworkDir=[Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory()
$NGENPath = Join-Path $FrameworkDir 'ngen.exe'

[AppDomain]::CurrentDomain.GetAssemblies() |
  Select-Object -ExpandProperty Location |
  ForEach-Object { & $NGENPath """$_""" } 

Read about ngen here.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .