none
Import-Module SqlPS running too slowly RRS feed

  • Question

  • Hi All,

    I have the following installed on a machine

    Windows Server 2008 R2
    SQL Server 2012 
    PowerShell 3
    Microsoft SQL Server 2012 Feature Pack Powershell tools

    My problem is that whenever i run a script that uses the invoke-sql scmdlet, it takes an huge amount of time. I believe this is because it is importing the module automatically each time (i.e. import module sqlps).

    Is there any way to install the invoke-sql cmdlet as an inbuilt feature of powershell? This would make my scripts run almost immediately instead of taking minutes as they do now. 



    • Edited by sdafa Tuesday, February 23, 2016 1:08 PM
    • Moved by Bill_Stewart Monday, May 2, 2016 3:41 PM Unanswerable drive-by question
    Tuesday, February 23, 2016 1:06 PM

All replies

  • No. The time is due to loading the server instance into the provider. That will happen every time you run the script.

    SQLPS is not  really a good simle execution environment. It is intended to be used to manage SQLServer instances.

    Use osql to avoid loading the provider or use ADO.Net.


    \_(ツ)_/

    Tuesday, February 23, 2016 1:17 PM
  • Just a thought but, If you installed the tools on a workstation with no SQLServer then it may also be the timeout looking for the local instance.\Try installing SQLExpress.  It should load much faster.

    On my workstation with now SQLServer installed "Import-Modute SQLPS" takes 3 seconds.


    \_(ツ)_/

    Tuesday, February 23, 2016 1:19 PM