DSC 错误中止

DSC Abort on Error

有没有办法让 DSC 在发生错误时中止其配置尝试,而不仅仅是继续配置中的下一个资源?

基本上,我想关闭 "on error resume next" 并执行 chef 所做的事情 - 出错时中止 运行。

如果您将 DependsOn 添加到您不想继续的任何资源,如果依赖链中的任何内容出现错误,它将中止。

Using DependsOn and this Whosebug answer describing dependencies

例如,在下面的配置中,如果组失败,将创建 none 个其他资源,因为 UserExample 依赖于 GroupExample,而 UserExample2 依赖于 UserExample。

Configuration DependsOnExample {
    Node Test-PC1 {
        Group GroupExample {
            Ensure = "Present"
            GroupName = "TestGroup"
        }

        User UserExample {
            Ensure = "Present"
            UserName = "TestUser"
            FullName = "TestUser"
            DependsOn = "[Group]GroupExample"
        }
        User UserExample2 {
            Ensure = "Present"
            UserName = "TestUser2"
            FullName = "TestUser2"
            DependsOn = "[User]UserExample"
        }
    }
}

目前没有一种方法可以在没有显式依赖的情况下获得相同的行为。

如果您想向产品团队请求该功能,我建议在 PowerShell User Voice

中提交问题

特拉维斯