Powershell does not recognize invoke-sqlcmd

15,368

I have similar problem:) This what i did: Register dll from sql files:

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" 

Then you can check by: get-PSSnapin -registered

and now add snapins:

Add-PSSnapin SqlServerCmdletSnapin100   
Add-PSSnapin SqlServerProviderSnapin100

That works for me. Hope it helps...

Sorry for my english:)

Share:
15,368
Jon
Author by

Jon

Updated on June 04, 2022

Comments

  • Jon
    Jon almost 2 years

    I am unable to use invoke-sqlcmd in powershell. I've loaded the module written by Chad Miller as described here: Problems using SQL Server 2008 R2 PowerShell extensions outside of SQLPS

    The module loads just fine without error, and using get-module shows sqlps as expected. However, using get-pssnapin does not show either SqlServerCmdletSnapin100 or SqlServerProviderSnapin100

    When I type invoke-sqlcmd I get the error "The term 'invoke-sqlcmd' is not recognized as the name of a cmdlet, function, script file, or operable program..."

    Running Windows 7 Pro, have SQL Server Management Studio Express 2008R2, have installed SQL Server 2008R2 Management Objects.

    Thanks for any help Jon