Slow Powershell scripts RRS feed

  • Question

  • I have two servers, both running Powershell 5 on WIndows 2012 R2. Running the same Powershell script on one of the serveres takes a LOT more time than the other. On one server (using Measure-Command) it takes around 5-6 seconds, on the other server 30-50 seconds. Servers are virtual and of similar capacity, load seems to be similar.



    $text = "Hello World"

    Invoked by (at an elevated command prompt):

    powershell -file c:\temp\Script.ps1

    I have tried:

    Invoking the script with powershell -noprofile -executionpolicy bypass -file c:\temp\Script.ps1

    Restarting the WMI service

    Running the script for generating cached images:

    $Env:PATH = [Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory()
    [AppDomain]::CurrentDomain.GetAssemblies() | % {
      $pt = $_.Location
      if (! $pt) {continue}
      if ($cn++) {''}
      $na = Split-Path -Leaf $pt
      Write-Host -ForegroundColor Yellow "NGENing $na"
      ngen install $pt

    I have run Process Monitorand on the slow server, it loks like below (script was invoked on time stamp 10:22:52,0000), so something is blocking:


    Any ideas?


    Friday, July 7, 2017 9:45 AM

All replies

  • There is obviously something different about the servers.  We cannot help you with this without access to the servers.


    Friday, July 7, 2017 10:10 AM