2

I installed PowerShell 4 yesterday and ever since then, I get the error "The term 'Invoke-Sqlcmd' is not recognized as the name of a cmdlet, function".

This has been working just fine for months until PowerShell 4.

I have SQL 2012 SP1 installed with CU7. VS 2013 with .NET 4.5.1. As far as I can tell, I have all the latest everything that PowerShell requires.

How can I get this fixed?

Invoke-Sqlcmd : The term 'Invoke-Sqlcmd' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1

1

I had similar issues getting invoke-sqlcmd to work without installing SQL Server Management Studio. What I found is that the bare minimum (without SSMS) needed to run invoke-sqlcmd are three files:

Microsoft® Windows PowerShell Extensions for SQL Server® 2008 R2

Microsoft® SQL Server® 2008 R2 Shared Management Objects

Microsoft® System CLR Types for SQL Server® 2008 R2

found here: http://www.microsoft.com/en-us/download/details.aspx?id=16978

Then open up Powershell and enter:

set-alias installutil $env:windir\Microsoft.NET\Framework\v2.0.50727\installutil

installutil -i "C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\Redist\Microsoft.SqlServer.Management.PSProvider.dll"
installutil -i "C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\Redist\Microsoft.SqlServer.Management.PSSnapins.dll"

Add-PSSnapin -Name SqlServerProviderSnapin100
Add-PSSnapin -Name SqlServerCmdletSnapin100

If you installed the 64-bit files you will need to run:

set-alias installutil $env:windir\Microsoft.NET\Framework\v2.0.50727\installutil

installutil -i "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\Redist\Microsoft.SqlServer.Management.PSProvider.dll"
installutil -i "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\Redist\Microsoft.SqlServer.Management.PSSnapins.dll"

Add-PSSnapin -Name SqlServerProviderSnapin100
Add-PSSnapin -Name SqlServerCmdletSnapin100

Also, make sure you are using the correct version of Powershell as the 64-bit version of Powershell cannot use the 32-bit version of "Microsoft.SqlServer.Management.PSSnapins.dll" and "Microsoft.SqlServer.Management.PSProvider.dll"

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.