当我尝试运行 powershell 脚本时,出现以下错误:
Invoke-Sqlcmd:术语“Invoke-Sqlcmd”未被识别为 cmdlet、函数、脚本文件或可操作程序的名称。
所以在 Powershell 中我运行了以下命令:
install-module sqlserver
update-module sqlserver
import-module sqlserver
这一切都运行良好。但是,当我重新运行脚本时,我仍然遇到相同的错误。
我还安装了 powershelltools.msi,它是作为 SQL Server 2014 功能包的一部分下载的:https://www.microsoft.com/en-gb/download/details.aspx?id=42295
如果我运行此命令:
Get-Command -Module sqlserver
我得到这个结果:
CommandType Name Version Source
----------- ---- ------- ------
Alias Decode-SqlName 21.0.17224 sqlserver
Alias Encode-SqlName 21.0.17224 sqlserver
Function SQLSERVER: 21.0.17224 sqlserver
关于我还应该尝试什么的任何想法?
我有 SQLServer 2014 和 Powershell 版本 5
最佳答案
您是否使用 Powershell Core (v6.1)?
我遇到了类似的问题并发现了这个SO answer 。事实证明,Powershell Core 的 SQLServer 模块不包含 Invoke-SqlCmd(以及其他)。我切换回在 Windows 10 (v5.1) 上安装的 64 位版本的 Powershell 并安装,然后导入 sqlserver 模块。 Invoke-SQLCmd 现已列出。
Install-Module -Name SqlServer -AllowClobber
Import-Module -Name SqlServer -Force
Get-Command -Module SqlServer
关于sql-server - SQL Powershell错误: Invoke-Sqlcmd : The term 'Invoke-Sqlcmd' is not recognized as the name of a cmdlet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48622914/