You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

安装SqlServer模块后仅显示Invoke-SqlNotebook,如何获取Invoke-Sqlcmd?

问题:PowerShell中Invoke-Sqlcmd命令未找到

问题详情

在Windows 11系统中运行Invoke-Sqlcmd时提示命令未找到,执行Get-Command -Module SqlServer仅返回Invoke-SqlNotebook命令。已尝试卸载、安装、导入、更新SqlServer模块,但问题仍未解决。

已执行的命令及输出

Install-Module -Name SqlServer -Force
Import-Module SqlServer
Get-Command -Module SqlServer

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Function        Invoke-SqlNotebook                                 22.1.1     SqlServer


Get-Module SqlServer

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     22.1.1                SqlServer                           Invoke-SqlNotebook

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Microsoft Windows 10.0.22621
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

解决方案

针对PowerShell 7.1.3(Core版本)出现的该问题,可尝试以下步骤:

  • 查看模块导入详情
    执行Import-Module SqlServer -Force -Verbose,观察输出信息,确认是否有命令未被正确导出或导入过程中存在错误。

  • 安装旧版本SqlServer模块
    部分新版本SqlServer模块(如22.x)在PS Core环境下可能仅包含有限命令。尝试安装21.x版本模块:

    Install-Module -Name SqlServer -RequiredVersion 21.1.18256 -Force
    Import-Module SqlServer
    Get-Command -Module SqlServer
    
  • 检查模块文件完整性
    定位SqlServer模块的安装路径(可通过(Get-Module SqlServer).Path查看),检查路径下是否存在Invoke-Sqlcmd相关的脚本文件(如Invoke-Sqlcmd.ps1),若缺失则重新安装模块。

  • 确认PowerShell版本兼容性
    SqlServer模块对PS Core版本有适配要求,若当前版本存在兼容性问题,可考虑升级PowerShell至7.2+版本后重新安装模块。

内容的提问来源于stack exchange,提问作者andrewjamesbowen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 11:30:13