Powershell运行Invoke-Sqlcmd命令的先决条件
运行Invoke-Sqlcmd命令,使用这个命令需满足如下条件:
1、在运行服务器中安装SQL Server 2008 R2 Management ObjectsI
2、在运行命令 invoke-sqlcmd 前执行如下语句.

1 Add-PSSnapin SqlServerCmdletSnapin100
2 Add-PSSnapin SqlServerProviderSnapin100
参考原文内容:
Since all of the steps I required weren't listed in one place, I thought I'd list them here in case it helps anyone:
- Install SQL Server 2008 R2 Management Objects using Web PI (I'm not sure about versions prior to 2008 R2... if you have more info, please let us know in the comments)
- Install 'Windows PowerShell Extensions for SQL Server' from the Microsoft® SQL Server® 2008 R2 Feature Pack page (it's about halfway down the page). Make sure you pick the correct flavor for your instance (32 or 64 bit).
- Run these two commands before calling invoke-sqlcmd in your script:
Add-PSSnapin SqlServerCmdletSnapin100
Add-PSSnapin SqlServerProviderSnapin100
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步