0
Why does a simple powershell script take a dozen or more seconds to run?
Here's the entire script (test-slow.ps1
):
write-host "test"
I call it like this, from a command prompt:
>echo %TIME%
15:07:12.64
>powershell .\test-slow.ps1
test
>echo %TIME%
15:07:26.81
If I start up a powershell instance from the cmd prompt and run this simple script from within that instance, there is no difference (or so little that it means there is still something else wrong).
System info:
PS> $PSVersionTable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
5 0 10240 16384
>systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
OS Name: Microsoft Windows 10 Pro
OS Version: 10.0.10240 N/A Build 10240
I am accessing the machine via Remote Desktop (wired connection, not Wireless), but it performs the same locally. It is on a local LAN but is NOT connected to the internet.
Why are you using 1507 instead of 1511 or 1607? – Ramhound – 2017-03-06T20:31:42.350
1
I would run Process Monitor (http://technet.microsoft.com/sysinternals/processmonitor.aspx) and launch the script. Initially I would add the Relative Time and Duration Columns and filter to Process Name is Powershell.exe. I would focus initially the just the Load Image times to see where the time is lost. For example is it quick to load all the modules? Could it be that there is some security software that is taking some time? Removing the filter for Powershell.exe and adding a Duration more than 0.1 might help. Either way, a PML will show you where the time is lost. Hope it helps.
– HelpingHand – 2017-03-06T20:56:51.570echo %time%&powershell .\test-slow.ps1&call echo %^time%
run it twice from an opencmd
window. Is a delay the same? – JosefZ – 2017-03-06T22:06:22.230@Ramhound, because I am working with a baseline image that other apps depend on. Does 1511 or later have an updated powershell? I don't mind installing an update to test that theory, but the box is not internet-connected - any way to apply an OS update offline? – atreyu – 2017-03-07T13:36:08.467
@JosefZ, I ran that command twice form an open
cmd
window, and the delay was the same (around 9-10 sec) – atreyu – 2017-03-07T13:36:50.687Spinning up a new copy of
powershell.exe
isn't going to be fast, is it. Start from apowershell.exe
prompt and then run the tests. – Bill_Stewart – 2017-03-08T00:19:32.863@Bill_Stewart, I tried precisely that already, and said so in my description (made no difference). – atreyu – 2017-03-08T20:21:46.883
That was not clear to me from your description, but in any case, I cannot reproduce the problem. – Bill_Stewart – 2017-03-08T20:33:41.847
I listed possible reasons I found while researching this problem here: https://stackoverflow.com/a/52030567/1026
– Nickolay – 2018-08-26T22:06:13.963