Mark Minasi's Reader Forum
Mark Minasi's Reader Forum
Home | Profile | Register | Active Topics | Active Polls | Members | Search | FAQ | Minasi Forum RSS Feed
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 HALP! Questions on Windows and Windows Server
 PowerShell
 PowerShell s-l-o-w to open
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mitachu
Honorable But Hopeless Addict

United Kingdom
1946 Posts
Status: offline

Posted - 05/30/2012 :  09:24:48 AM  Show Profile  Click to see mitachu's MSN Messenger address  Reply with Quote
Powershell seems to take ages to open up on some servers. Is there something I can be looking at? I don't think these servers are going to have a profile that's being loaded and taking a long time as they're often fresh installs.

Tim

Xenophane
Honorable But Hopeless Addict

Denmark
3070 Posts
Status: offline

Posted - 05/30/2012 :  09:27:38 AM  Show Profile  Visit Xenophane's Homepage  Send Xenophane an ICQ Message  Reply with Quote
PowerTip of the Day, from PowerShell.com:

Optimizing PowerShell Performance

PowerShell is loading .NET assemblies. These assemblies can be precompiled using the tool ngen.exe which improves loading times (because the DLLs no longer have to be compiled each time they are loaded).

Before you think about optimizing the DLLs PowerShell uses, you should do some reading on ngen.exe and its benefits. Then, you could use the following code to optimize all DLLs loaded by PowerShell. You do need Administrator privileges for this.

$FrameworkDir=[Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory()
$NGENPath = Join-Path $FrameworkDir 'ngen.exe'
[AppDomain]::CurrentDomain.GetAssemblies() |
Select-Object -ExpandProperty Location |
ForEach-Object {
& $NGENPath """$_"""
}

Microsoft Powershell MVP

SIG> George Bernard Shaw : The power of accurate observation is commonly called cynicism by those who have not got it. </SIG>

You can read my blog at www.xipher.dk
Go to Top of Page

mitachu
Honorable But Hopeless Addict

United Kingdom
1946 Posts
Status: offline

Posted - 05/30/2012 :  09:36:50 AM  Show Profile  Click to see mitachu's MSN Messenger address  Reply with Quote
Thanks for that.

I take it this can cause problems?

Tim
Go to Top of Page

Xenophane
Honorable But Hopeless Addict

Denmark
3070 Posts
Status: offline

Posted - 05/30/2012 :  09:58:19 AM  Show Profile  Visit Xenophane's Homepage  Send Xenophane an ICQ Message  Reply with Quote
I have not experienced problems with it... But on the other hand I have not done this large scale in our server environment either, since most time I use my local machine or a jump host.

Microsoft Powershell MVP

SIG> George Bernard Shaw : The power of accurate observation is commonly called cynicism by those who have not got it. </SIG>

You can read my blog at www.xipher.dk
Go to Top of Page

jhicks
Here To Stay

USA
283 Posts
Status: offline

Posted - 05/30/2012 :  10:03:37 AM  Show Profile  Visit jhicks's Homepage  Reply with Quote
Periodically I do this on my Win7 box and have noticed an improvement in load time. This is the script I use:


#requires -version 2.0
Set-Alias ngen (Join-Path ([System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory()) ngen.exe)

[AppDomain]::CurrentDomain.GetAssemblies() |
Where {$_.Location} |
sort {Split-path $_.location -leaf} |
%{
$Name = (Split-Path $_.location -leaf)
if ([System.Runtime.InteropServices.RuntimeEnvironment]::FromGlobalAccessCache($_))
{
Write-Host "Already GAC'ed: $Name" -fore CYAN
}else
{
Write-Host -ForegroundColor Yellow "NGEN'ing : $Name"
ngen $_.location | %{"`t$_"}
}
}

Jeffery Hicks
Windows PowerShell MVP

http://jdhitsolutions.com.blog
http://twitter.com/JeffHicks
http://www.ScriptingGeek.com
Now Available: Managing Active Directory with Windows PowerShell: TFM 2nd ed.
Go to Top of Page

mitachu
Honorable But Hopeless Addict

United Kingdom
1946 Posts
Status: offline

Posted - 05/30/2012 :  10:08:25 AM  Show Profile  Click to see mitachu's MSN Messenger address  Reply with Quote
I just ran that on my laptop after running the first suggestion and got the following output:

PS C:\Users\tim.wiser\Documents\Work\n-able\n-able scripts by me> .\OptimisePowerShell2.ps1
Already GAC'ed: Microsoft.PowerShell.Commands.Diagnostics.dll
Already GAC'ed: Microsoft.PowerShell.Commands.Management.dll
Already GAC'ed: Microsoft.PowerShell.Commands.Utility.dll
Already GAC'ed: Microsoft.PowerShell.ConsoleHost.dll
Already GAC'ed: Microsoft.PowerShell.Security.dll
Already GAC'ed: Microsoft.WSMan.Management.dll
Already GAC'ed: mscorlib.dll
Already GAC'ed: System.Configuration.Install.dll
Already GAC'ed: System.Core.dll
Already GAC'ed: System.Data.dll
Already GAC'ed: System.DirectoryServices.dll
Already GAC'ed: System.dll
Already GAC'ed: System.Management.Automation.dll
Already GAC'ed: System.Management.dll
Already GAC'ed: System.Transactions.dll
Already GAC'ed: System.Xml.dll
PS C:\Users\tim.wiser\Documents\Work\n-able\n-able scripts by me>


Perhaps it does the same thing?

Tim
Go to Top of Page

jhicks
Here To Stay

USA
283 Posts
Status: offline

Posted - 05/30/2012 :  10:17:06 AM  Show Profile  Visit jhicks's Homepage  Reply with Quote
That looks right. If PowerShell is still slow to open, then something else is going on. Could this be as simple as needing to defrag the disk?

Jeffery Hicks
Windows PowerShell MVP

http://jdhitsolutions.com.blog
http://twitter.com/JeffHicks
http://www.ScriptingGeek.com
Now Available: Managing Active Directory with Windows PowerShell: TFM 2nd ed.
Go to Top of Page

Playwell
Honorable But Hopeless Addict

Netherlands
4818 Posts
Status: offline

Posted - 05/30/2012 :  10:25:51 AM  Show Profile  Visit Playwell's Homepage  Click to see Playwell's MSN Messenger address  Reply with Quote
If the workstation has no direct internet access unmark this option in IE:
'Check for publisher's certificate revocation' under advanced

'People who think they know everything are a great annoyance to those of us who do. '
Quote by Isaac Asimov


Go to Top of Page

mitachu
Honorable But Hopeless Addict

United Kingdom
1946 Posts
Status: offline

Posted - 05/30/2012 :  10:41:22 AM  Show Profile  Click to see mitachu's MSN Messenger address  Reply with Quote
quote:
Originally posted by Playwell

If the workstation has no direct internet access unmark this option in IE:
'Check for publisher's certificate revocation' under advanced



Yep, done that already. The server has Internet access but I thought I'd give it a shot anyway.

Tim
Go to Top of Page

jhicks
Here To Stay

USA
283 Posts
Status: offline

Posted - 05/30/2012 :  11:13:05 AM  Show Profile  Visit jhicks's Homepage  Reply with Quote
You might want to double-check and verify there are no profiles. Run this command and see if any of these are true:

PS S:\> $profile.CurrentUserAllHosts, $profile.CurrentUserCurrentHost, $profile.AllUsersAllHosts, $profile.AllUsersCurrentHost | test-path

Jeffery Hicks
Windows PowerShell MVP

http://jdhitsolutions.com.blog
http://twitter.com/JeffHicks
http://www.ScriptingGeek.com
Now Available: Managing Active Directory with Windows PowerShell: TFM 2nd ed.
Go to Top of Page

JeffWouters
Here To Stay

Netherlands
147 Posts
Status: offline

Posted - 05/31/2012 :  04:00:53 AM  Show Profile  Visit JeffWouters's Homepage  Click to see JeffWouters's MSN Messenger address  Look at the Skype address for JeffWouters  Reply with Quote
Indeed, check your profiles... also check what's in them, one of my colleagues had one consisting of more than 700 lines :-S

Greetsz,
Jeff.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Mark Minasi's Reader Forum © 2002-2011 Mark Minasi Go To Top Of Page
This page was generated in 0.12 seconds. Snitz Forums 2000