sql-server - SQL Powershell错误: Invoke-Sqlcmd : The term 'Invoke-Sqlcmd' is not recognized as the name of a cmdlet

标签 sql-server powershell

当我尝试运行 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/

相关文章:

.net - 如何解决间歇性 SQL 超时错误

SQL Server : REPLACE function replace ' ' with ',' in string

SQL Server 舍入错误,给出不同的值

c# - SQL 查询 : Select Column1, 行数 (criteria1),行数 (criteria2)

string - 分割路径并仅取出最后一部分(文件名)Powershell

用于查看当前登录用户(域和机器)+状态(事件、空闲、离开)的 Powershell 脚本

SQL选择底部记录

perl - Powershell主机文件编辑

Powershell Get-Acl 所有者引用

powershell - 列出所有域计算机上的本地管理员组成员身份