无法 运行 处于所需状态配置的节点和脚本

Unable to run Node and Script in Desired State Configuration

背景

我正在使用 ARM 模板在 Azure 中配置 VM,并创建了一个 Desired State Configuration .ps1 文件来安装和配置 IIS。到目前为止一切顺利。

然后我在 Node 块旁边添加了一个 Script 块。

当前设置:

Configuration Main
{
    Param ( [string] $nodeName )

    Import-DscResource -ModuleName PSDesiredStateConfiguration

    Node $nodeName
    {
        WindowsFeature WebServer
        {
            Name = "Web-Server"
            Ensure = "Present"
        }

        #other WindowsFeatures
    }

    Script FormatDiskScript
    {
        SetScript =
        {
            #Powershell to format disks
        }
        TestScript = { return $false }
        GetScript = { }
    }
}

在我的 ARM 模板中,我已将 DSC 扩展添加到我的 VM 并指定 url 从哪里获取 zip 文件,script 到 运行 和 function 调用。

"properties": {
  "publisher": "Microsoft.Powershell",
  "type": "DSC",
  "typeHandlerVersion": "2.23",
  "autoUpgradeMinorVersion": true,
  "settings": {
    "configuration": {
      "url": "[concat(parameters('_artifactsLocation'), '/', variables('dscArchiveFolder'), '/', variables('webvm_dscZipFileName'))]",
      "script": "webvm-dsc.ps1",
      "function": "Main"
    },
    "configurationArguments": {
      "nodeName": "[variables('webvm_name')]"
    }
  },
  "protectedSettings": {
    "configurationUrlSasToken": "[parameters('_artifactsLocationSasToken')]"
  }
}

问题

它生成两个 .mof 文件并执行 NodeScript 部分,但只有 Node 部分成功完成。

当我 运行 仅与 Script 一起工作时,Script 有效。我只是在 运行ning 他们两个时才遇到问题。

这是我在 C:\Packages\Plugins\Microsoft.Powershell.DSC.23.0.0\Status[=51=].status

中看到的输出
Settings handler status to 'transitioning' 
Updating execution status 
DSC configuration completed
No meta mof back up file exist to restore ...
Settings handler status to 'error' 

回答

在尝试了不同的方法之后,我终于偶然发现了一种有效的方法。我只是将 Script 放在 Node 中,而不是将其作为对等项:

Configuration Main
{
    Param ( [string] $nodeName )

    Import-DscResource -ModuleName PSDesiredStateConfiguration

    Node $nodeName
    {
        WindowsFeature WebServer
        {
            Name = "Web-Server"
            Ensure = "Present"
        }

        #other WindowsFeatures

        Script FormatDiskScript
        {
             SetScript =
             {
                 #Powershell to format disks
             }
             TestScript = { return $false }
             GetScript = { }
        }
    }
}

您需要在 DSC 配置中创建 2 个配置(比如 Main 和 Manual),并将您想要使用 ARM 模板执行的内容放入 main 中,将其他内容放入 manual

或者在 2 个单独的文件中创建 2 个单独的配置。