SQLPS module is slow to load - by Chrissy LeMaire

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


106
1
Sign in
to vote
ID 2429153 Comments
Status Closed Workarounds
Type Bug Repros 5
Opened 3/2/2016 10:36:32 PM
Access Restriction Public

Description

SQLPS dot sources a file which performs an inefficient PowerShell call. This wait time is so excessive, it discourages use of PowerShell within the SQL Server community. 

Using one line of optimized PowerShell code decreases module import load time from about 2-4 seconds to 200-400 milliseconds.

Lines 7 and 8 in SqlPSPostScript.ps1 (expand Details on where to find it) should be removed 

$m = Get-Module -ListAvailable | where {$_.Name -eq "SQLASCmdlets"}
if($m -ne $null) { Import-Module $m -Global }

And the following should be added:

Import-Module SQLASCmdlets -Global -ErrorAction SilentlyContinue

or alternatively, the community has suggested these other possibilities:

try { Import-Module SQLASCmdlets -Global -ErrorAction Stop} catch { Write-Verbose "Unable to import SQLASCmdlets module" }
or
try { Import-Module SQLASCmdlets -Global -ErrorAction Stop} catch [System.IO.FileNotFoundException] { Write-Verbose "Unable to locate SQLASCmdlets" }
or
Use RequiredModules in the SQLPS module manifest
or
Use #requires in SqlPsPostScript.ps1 (and anywhere else that SQLASCmdlets is required)
Sign in to post a comment.
Posted by Chrissy LeMaire on 4/4/2016 at 12:36 PM
Most beautiful Resolved as Fixed I've ever seen <3! Thank you all!
Posted by Microsoft on 4/4/2016 at 12:21 PM
Hi Chrissy,
Thanks for reporting this issue. We loooked into it and we fixed in RC2.