Ris*_*rks 5 powershell import-module executionpolicy sqlps
Windows 7 工作站 POSH 3.0 SS 2012 SP1
摘要:
Developer 1 无法运行 Invoke-SQLCmd
Developer 2 具有类似 SS Client 工具安装可以运行 Invoke-SQLCmd
Developer 1 无法运行 Import-Module SQLPS
当我尝试从笔记本电脑运行查询时,如下所示:
Invoke-sqlcmd -ServerInstance <ServerName> -Query "Select top 10 * from <SomeTable>;"
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Invoke-sqlcmd : The 'Invoke-sqlcmd' command was found in the module 'SQLPS',
but the module could not be loaded. For more information, run 'Import-Module
SQLPS'.
Run Code Online (Sandbox Code Playgroud)
另一位开发人员可以成功运行该命令,并且我们都有本地
由于明显的原因,我无法在我的计算机上运行导入模块 sqlps - ExecutionPolicy 受到限制。
我不确定为什么其他开发人员的机器允许查询,而我的机器不允许。这是 SQL 客户端安装问题吗?
这都是关于微软的。他们拥有最好的技术,但不仅仅是使用其工具的一种方式和直接途径。:( 您可以使用 SMO 对象与数据库交互。(您可以将其与 C#/VB.net/PowerShell 一起使用) :$ 您可以使用 SQLPS 您可以使用 Invoke-SQLCmd
只需运行下面的脚本即可确保您的计算机中安装了功能包并使用 SQLPS,它比其他解决方案更易于使用(个人偏好)
Install-module -Name SqlServer -Scope CurrentUser
# Import the SQL Server Module.
Import-Module Sqlps -DisableNameChecking;
# To check whether the module is installed.
Get-Module -ListAvailable -Name Sqlps;
cd SQLSERVER:\SQL
Run Code Online (Sandbox Code Playgroud)
也许您可以尝试下面的\n Add-PSSnapin SqlServerCmdletSnapin100\n Add-PSSnapin SqlServerProviderSnapin100\n虽然我注意到这些管理单元没有安装在我的本地,但我可以使用 SQLPS,但这可能是因为执行策略不受限制。\ n来源:SQL 权威
\n\n更新:按以下顺序下载并安装
\n\n链接 - https://www.microsoft.com/en-us/download/details.aspx?id=29065
\n| 归档时间: |
|
| 查看次数: |
37638 次 |
| 最近记录: |