powershell - DSC 出错时中止

标签 powershell dsc powershell-5.0

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

基本上,我想关闭“下一步出错时恢复”并执行厨师所做的操作 - 出错时中止运行。

最佳答案

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

参见Using DependsOnthis StackOverflow answer describing dependencies

例如,在下面的配置中,如果组失败,则不会创建任何其他资源,因为 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 中提交问题

特拉维斯

关于powershell - DSC 出错时中止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36992681/

相关文章:

Powershell - LastLogonDate 距今天已超过 90 天

powershell - 使用 Powershell 阅读 Gmail 电子邮件

powershell - 如何使用 WMI 和 Powershell 保存对 Windows 组的更改

azure - 如何使用 VSTS DSC 配置自动将软件安装到 Azure VM 上

powershell - 如何在 powershell DSC 中正确写入参数

powershell - 如何在PowerShell完成之前中断和停止TTS引擎?

powershell - 卸载组件

azure - 使用 PowerShell 更改 Azure VM 的密码

powershell - 重新启动后重新获取DSC后台作业

windows - PowerShell WindowStyle -Hidden 适用于 Windows 10,但不适用于 Windows 7