FIX: Invoke-SqlCmd Is Not Recognized in PowerShell on Windows 8.1 and 2012

The other day, I was trying to run the SQL Server PowerShell cmdlets on my main workstation, a Surface Pro 3 with Visual Studio 2013, SQL 2012 Mgmt Studio and management objects loaded.

Attempts to run invoke-sqlcmd returned the following:

Attempts to load the SQL snap-in (SQL 2008 I believe), like so:

Add-PSSnapin SqlServerCmdletSnapin100
Add-PSSnapin SqlServerProviderSnapin100

resulted in the following error:

Add-PSSnapin : The Windows PowerShell snap-in ‘SqlServerCmdletSnapin100’ is not installed on this computer.

Attempting with import-module sqlps resulted in a similar “not found” error.

With all the components I had loaded, I found this a bit unusual, but needed a quick fix.

The Fix

After a lot of messing around with a couple of articles on this issue on the Internet without success, I came across a support thread that included the following fix, though not well-documented.

On the Start screen, type Visual Studio Tools.

image

 

Find the 64-bit version of the Visual Studio Command Prompt (VS2013 x64 Native Tools Command Prompt), right click and select Run As Administrator.

 

image

From the prompt, run the following commands. (A note on installutil.exe here). Make sure the path to the .dlls matching

installutil “C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules\SQLPS\Microsoft.SqlServer.Management.PSProvider.dll”
installutil “C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules\SQLPS\Microsoft.SqlServer.Management.PSSnapins.dll”

Now, importing the SQL PowerShell cmdlets with import-module SQLPS works like a charm.

Important Additional Reading

If “DevOps” is not on your radar, you should have a look…and soon. We have a great series here on System Center Central titled “100 Days of DevOps with PowerShell”. It’s a great way to get up to speed on the subjects and learn all about PowerShell DSC in the process. I encourage you to have a look.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.