简体   繁体   English

如何将SQLPS模块导入Azure自动化?

[英]How to import SQLPS module into Azure Automation?

I'm trying to connect to a Azure SQL server (under a different subscription) using SQLPS 我正在尝试使用SQLPS连接到Azure SQL服务器(在不同的订阅下)

Auth method is SQL server auth. 身份验证方法是SQL Server身份验证。

When I try to import-module SQLPS, I get this error: 当我尝试导入模块SQLPS时,出现以下错误:

Error: import-module : The specified module 'sqlps' was not loaded because no valid module file was found in any module directory. 错误:import-module:未加载指定的模块'sqlps',因为在任何模块目录中均未找到有效的模块文件。

While I'm able to connect to the same Azure SQL server from windows powershell, I have no clue why I'm not able to perform the same on Azure Powershell. 虽然我可以从Windows Powershell连接到相同的Azure SQL服务器,但是我不知道为什么我不能在Azure Powershell上执行相同的操作。 I understand that appropriate .psm1 modules should exist for powershell to understand this, but can someone help me on how to do it? 我知道应该有适当的.psm1模块供Powershell理解,但是有人可以帮助我做些什么吗?

I have tried exporting/importing the module from 我尝试从中导出/导入模块

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

and didn't workout too... 而且也没有锻炼...

Just to answer this question on 2 possible solutions I found: 只是针对我发现的2种可能的解决方案来回答这个问题:

  1. You can use Azure custom script extension to inject the script into the VM that that you want to restore to. 您可以使用Azure自定义脚本扩展将脚本注入到要还原到的VM中。 The script will then run locally on the VM which means the SQL PS will be available. 然后,该脚本将在VM上本地运行,这意味着SQL PS将可用。

  2. You can setup a VM in Azure as a Hybrid worker which then becomes your "Azure Automation machine". 您可以在Azure中将VM设置为Hybrid worker,然后成为您的“ Azure Automation计算机”。 You can then install SQLPS or any module that you require on that server. 然后,您可以在该服务器上安装SQLPS或所需的任何模块。

The error you are getting is simply PowerShell telling you that it probled all the folders specified in your $env:PSModulePath (ie %PSMODULEPATH% env variable) and it did not find the SQLPS module (its manifest file, basically). 您得到的错误只是PowerShell告诉您,它使$ env:PSModulePath中指定的所有文件夹(即%PSMODULEPATH%env变量)出现问题,并且找不到SQLPS模块(基本上是清单文件)。

I am not clear how you are "exporting/importing" the SQLPS. 我不清楚您如何“导出/导入” SQLPS。 Could you elaborate on that? 您能详细说明一下吗?

On a clean machine without SQLPS (ie with no SQL Engine nor SQL Management Studio), I would just rely on the SQL Feature Pack to get SQLPS. 在没有SQLPS的干净机器上(即没有SQL Engine或SQL Management Studio),我将仅依靠SQL Feature Pack来获取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. 如果这是您要完成的工作,则可以转到https://www.microsoft.com/zh-cn/download/details.aspx?id=42295并下载以下MSI(选择操作系统的体系结构) ):-SQLSysClrTypes.mai-SharedManagementObjects.msi-PowerShellTools.msi依次安装。 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. 然后,当您打开PowerShell窗口时,应该正确设置$ env:PSModulePath,并且您应该能够只说“导入模块SQLPS -DisableNameChecking”并开始使用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 谢谢,-Matteo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM