Friday, July 11, 2008

Speed up PowerShell startup times

For long time I am using script Speed-Startup.ps1. It is part of my automated PowerShell installation. I try to keep all my PS-related stuff (scripts, profiles) subversioned - easy to use, free, easy to setup and it already saved me few times.

$NgenLocation = @($(dir -Path (join-path ${env:\windir} "Microsoft.NET\Framework") -Filter "ngen.exe" -recurse) | sort -descending lastwritetime)[0].fullName

If ($(Test-Path -PathType Leaf -Path $NgenLocation)) {
$CurrentAccount = new-object System.Security.Principal.WindowsPrincipal([System.Security.Principal.WindowsIdentity]::GetCurrent())
$Administrator = [System.Security.Principal.WindowsBuiltInRole]::Administrator

If ($CurrentAccount.IsInRole($Administrator)) {
[appdomain]::currentdomain.getassemblies() | ForEach {. $NgenLocation $_.Location}
} Else {
Write-host -ForegroundColor Red "You must be local administrator."

} Else {
Write-host -ForegroundColor Red "Ngen.exe was not found"


You should always run it, because sometimes assemblies are not ngened and PowerShell load is slooooooooow... I just noticed that Jeffrey posted reminder how to speed startup.

I am however curious if there is any way to pre-load .NET environment if you use PowerShell for your logon scripts in Terminal Services\Citrix environment (that means environment where multiple users are logged on to same server).



No comments: