简体   繁体   English

Azure PowerShell DSC安装额外的模块

[英]Azure PowerShell DSC install extra modules

As part of an Azure resource group template I have a PowerShell DSC extension setup for my VM which provisions various Windows features. 作为Azure资源组模板的一部分,我为我的VM提供了PowerShell DSC扩展设置,它提供了各种Windows功能。

As part of this automated setup I want to be able to open some ports in the firewall, after a bit of research I found there is a xFirewall DSC module available. 作为这种自动化设置的一部分,我希望能够在防火墙中打开一些端口,经过一些研究后我发现有一个xFirewall DSC模块可用。 My problem is how can I automatically install this module onto the Azure VM before the DSC executes? 我的问题是如何在DSC执行之前自动将此模块安装到Azure VM上?

My configuration looks like this: 我的配置如下所示:

Configuration Main
{

Param ( [string] $nodeName )

Import-DscResource -ModuleName PSDesiredStateConfiguration
Import-DscResource -ModuleName xFirewall

Node $nodeName

The import of xFirewall fails because the module is not installed. 导入xFirewall失败,因为未安装模块。

I have thought about creating another DSC script that could run before this one, but that proves difficult as you can only have one DSC extensions attached to a VM at a time. 我已经考虑过创建另一个可以在此之前运行的DSC脚本,但这证明很难,因为你一次只能有一个DSC扩展连接到VM。

The module you need to import is the xNetworking module and the resource is xFirewall. 您需要导入的模块是xNetworking模块,资源是xFirewall。 So, a simple example of the DSC script would look like this. 因此,DSC脚本的一个简单示例如下所示。

Configuration Main
{

Param ( [string] $nodeName )

Import-DscResource -ModuleName PSDesiredStateConfiguration
Import-DscResource -ModuleName xNetworking

Node $nodeName
  {
      xFirewall Firewall 
      { 
          Name    = "AllowNotepad"             
          Program = "c:\windows\system32\notepad.exe" 
          Action  = "Allow" 
      } 
  }
}

To get this into your Resource Group deployment template, you need to copy the xNetworking module into your project under the DSC folder that was created when you added the PowerShell DSC Extensions. 要将其添加到资源组部署模板中,需要将xNetworking模块复制到添加PowerShell DSC Extensions时创建的DSC文件夹下的项目中。 Then add the xNetworking folder to your project as shown here. 然后将xNetworking文件夹添加到项目中,如下所示。

在此输入图像描述

Next, go through your normal Deploy process. 接下来,完成正常的部署过程。 What will be different now that you have a DSC extension is that you will need to specify an artifacts storage account prior to deploying. 现在您有DSC扩展的不同之处在于,您需要在部署之前指定工件存储帐户。

在此输入图像描述

The Deploy-AzureResourceGroup.ps1 script in your project will upload the DSC.zip which now includes your xNetworking module into the storage account so that Azure Resource Manager (ARM) can then push the extension into the virtual machine after it has been provisioned. 部署-AzureResourceGroup.ps1脚本在您的项目将上传DSC.zip现在包括您xNetworking模块插入存储帐户,以便Azure的资源管理器(ARM),然后推扩展到虚拟机已经置备 From there, the DSC engine in the virtual machine takes over and applies the configuration. 从那里,虚拟机中的DSC引擎接管并应用配置。

Refer to How to use and discover DSC resources in this article 请参阅如何使用和发现DSC资源文章

Assuming you dropped xFirewall module as part of the DscResource, First you need import the module, I think that's xNetworking , by using Import-Module {FullPath} then follow by Import-DSCResource -ModuleName xNetworking -name xFirewall 假设您将xFirewall模块作为DscResource的一部分丢弃,首先您需要导入模块,我认为是xNetworking ,使用Import-Module {FullPath}然后按Import-DSCResource -ModuleName xNetworking -name xFirewall

Or try Import-DSCResource -Name xFirewall , seems this will make it scan the entire resource folder and find the xFirewall for you. 或者尝试使用Import-DSCResource -Name xFirewall ,这似乎会使它扫描整个资源文件夹并为您找到xFirewall。

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

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