How To Import SQLPS While Keeping The Current PowerShell Provider

One of the very few annoyances of using the SQL PowerShell Provider becomes apparent when you import its module. Your current location, probably a working folder somewhere in your file system, will get overridden by the default location of the new provider.

To avoid this behaviour, you can include a function like the one below in your scripts.
This will hold on to your current location, import the module and then reset your location to what it was before.

function Import-SQLPS
    $Current = Get-Location
    Import-Module SQLPS -DisableNameChecking
    Set-Location $Current

Index: PowerShell HowTo’s


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s