How to register PowerShell SQL server snapin in Windows preinstalled PowerShell

When you have installed Sql server, you probably noticed that your PoweShell is not able to run common SQL scriptlets and you have to start it to run them from SQL server Management Studio or with SQLPS.exe command. But it is easy to enable running SQL commands from regular PowerShell shell.

Checking whether SQL server snapin is working

When you see following result to Get-Help SQLserver, your snapin is either not registered correctly or not added to interactive console as a snapin.

PS C:\Users\Martin> Get-Help SQLServer

Name                              Category  Synopsis
—-                              ——–  ——–
Get-WSManInstance                 Cmdlet    Displays management information for a resource instance specified by a R…
Get-Help                          Cmdlet    Displays information about Windows PowerShell commands and concepts.

To see all registered snapins, you can type:

get-PSSnapin –registered

Name        : SqlServerCmdletSnapin100
PSVersion   : 2.0
Description : This is a PowerShell snap-in that includes various SQL Server cmdlets.

Name        : SqlServerProviderSnapin100
PSVersion   : 2.0
Description : SQL Server Provider

You should see these two items registered SqlServerCmdletSnapin100 and SqlServerProviderSnapin100.

When you dont have your snapins registered, type following commands:

PS C:\Users\Martin> set-alias installutil $env:windir\\framework\v2.0.50727\installutil

PS C:\Users\Martin> installutil -i “c:\Program Files\Microsoft SQL Server\100\Tools\Binn\Microsoft.SqlServer.Management.


PS C:\Users\Martin> installutil -i “c:\Program Files\Microsoft SQL Server\100\Tools\Binn\Microsoft.SqlServer.Management.

Note: path of your




could be different on your Sql server installation. (On 2008 RTM its C:\Program Files\Microsoft SQL Server\100\Tools\Binn\Redist\)

On my Sql server 2008 R2 machine, these snapins were correctly registered, so I skipped previous step.

After registration your snapins, you should add them to your interactive powershell console. To do this, you should type:

PS C:\Users\Martin> Add-PSSnapin SqlServerCmdletSnapin100
PS C:\Users\Martin> Add-PSSnapin SqlServerProviderSnapin100

After this step, you should have no problem to get any of sql server scriptlets running, we can test with help again:

PS C:\Users\Martin> Get-Help SQLServer


    SQLSERVER, SQL, SQLPolicy, SQLRegistration

    Access SQL Server instances and their databases.


Adding sql server snapin to your PowerShell at shell start

Instead of adding two snapins manually all the time, you can let powershell to start them in profile scriptlet.

Profile scriptlet is something that (if exists) is started for all users or specifically only for you.

All Users – this scriptlet should be in %windir%\system32\WindowsPowerShell\v1.0\profile.ps1

Only you – C:\Documents and Settings\%username%\My Documents\WindowsPowerShell\profile.ps1 or its equivalent.

On my Windows 7, profile.ps1 is located in (You should create new one if it does not exist)


My profile.ps1 file looks like this:

Add-PSSnapin SqlServerCmdletSnapin100
Add-PSSnapin SqlServerProviderSnapin100
“Welcome to PowerShell with SQL server snapin”

Before you restart shell, you should also allow running unsigned scripts (like is profile.ps1). To do this, type following:

set-executionpolicy unrestricted

And now, you can restart PowerShell session and Snapin should work correctly. You can use this even in PowerShell ISE (Integrated Script Environment)

Note: After creating profile.ps1 file, you can get Following error when starting SQLPS.EXE (or Management Studio PowerShell)

The term ‘Add-PSSnapin’ is not recognized as the name of a cmdlet, function, sc
ript file, or operable program. Check the spelling of the name, or if a path wa
s included, verify that the path is correct and try again.

This error appears because of SQLPS is a limited PowerShell host that does not implement Add-PSSnapin. It should be used only for sql server management and when you need to use more snapins or scriptlets, use regular PowerShell host instead.

4 thoughts on “How to register PowerShell SQL server snapin in Windows preinstalled PowerShell

  1. Hi Martin. Thanks for the article. I have tried everything you suggested but I still can’t get SqlServerCmdletSnapin100 and SqlServerProviderSnapin100 to show up when I run the command Get-PSSnapin -Registered. With your commands I ensured that mine were pointing to the correct path which in my case is: installutil -i “C:\Program Files\Microsoft SQL Server\110\Tools\PowerShell\Modules\SQLPS\Microsoft.SqlServer.Management.PSSnapins.dll” But still doesn’t work 😦 Why is this happening? I’ve been struggling with this for more than a week 😦

    1. Hi Ciwan,
      from your description it seems you are using installutil from a .NET runtime folder, which is different from your PowerShell runtime version.
      To find out which .NET your Powershell shell is using, please invoke:
      If you see v. 2, then the the installutil should be from above, but if you see v. 4, then you should change installutil alias into:
      set-alias installutil $env:windir\\framework\v4.0.30319\installutil

      You can also verify installutil version, after typing running just installutil, it will show this utility version too.

      So generally, make sure your PowerShell version match installutil tool version.

  2. Hi Martin. Much appreciated article as this seems to be a very common issue for many.

    However I have worked through all of the steps and am still having no luck. Both of the installutil steps complete successfully but when I try to use Add-PSSnapin steps it goes back to telling me “No snap ins have been registered for Windows Powershell Version 2. Any other suggestions? The PowerShell application I use is running from the System32 folder which I assume is correct.

    Any help would be much appreciated. Thank you!!!

  3. Thanks for your article. The article is great .For me everything is working fine. I have question. In my server I don’t have SQL install. But I m running PowerShell(Ex: Execute SQL Script) in Windows server .I am getting error. So I have to ask to admin to install .net\framework\ and \Tools\Binn\Microsoft.SqlServer.Management. PSProvider.dll”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

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

Google photo

You are commenting using your Google 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 )

Connecting to %s