0

我正在尝试使用 SQLPS 连接到 Azure SQL 服务器(在不同的订阅下)

Auth方法是SQL server auth。

当我尝试导入模块 SQLPS 时,出现此错误:

错误:import-module:未加载指定的模块“sqlps”,因为在任何模块目录中都找不到有效的模块文件。

虽然我可以从 windows powershell 连接到同一个 Azure SQL 服务器,但我不知道为什么我不能在 Azure Powershell 上执行相同的操作。我知道powershell应该存在适当的.psm1模块来理解这一点,但是有人可以帮助我如何做到这一点吗?

我已经尝试从

C:\Program Files\Microsoft SQL Server\120\Tools\PowerShell\Modules

也没有锻炼...

4

2 回答 2

0

只是为了回答这个问题,我发现了 2 个可能的解决方案:

  1. 可以使用 Azure 自定义脚本扩展将脚本注入到要还原到的 VM。然后该脚本将在 VM 上本地运行,这意味着 SQL PS 将可用。

  2. 您可以在 Azure 中将 VM 设置为混合工作器,然后它会成为您的“Azure 自动化机器”。然后,您可以在该服务器上安装 SQLPS 或您需要的任何模块。

于 2017-11-27T22:08:14.890 回答
-1

The error you are getting is simply PowerShell telling you that it probled all the folders specified in your $env:PSModulePath (i.e. %PSMODULEPATH% env variable) and it did not find the SQLPS module (its manifest file, basically).

I am not clear how you are "exporting/importing" the SQLPS. Could you elaborate on that?

On a clean machine without SQLPS (i.e. with no SQL Engine nor SQL Management Studio), I would just rely on the SQL Feature Pack to get SQLPS. If this is what you are trying to accomplish, you can just go to https://www.microsoft.com/en-us/download/details.aspx?id=42295 and download the following MSIs (pick the architecture of your OS): - SQLSysClrTypes.mai - SharedManagementObjects.msi - PowerShellTools.msi Install them in that order. Then, when you open a PowerShell window, the $env:PSModulePath should be set correctly and you should be able to just say "Import-Module SQLPS -DisableNameChecking" and get going with SQLPS.

Please, let me know if this is not what you are trying to do or you are running into other issues. If you give me more details, I might be able to help you out.

Thanks, -Matteo

于 2016-04-18T20:34:03.067 回答