配置DSC资源以重新启动

Dam*_*anB 6 powershell dsc powershell-5.0

我有一个DSC资源,安装dotnet功能,然后安装更新到dotnet.

在我设置的本地配置管理器RebootNodeIfNeeded$true.

安装dotnet后,它不会请求重启(甚至使用xPendingReboot模块来确认).

Configuration WebServer
{
WindowsFeature NetFramework45Core
{
    Name = "Net-Framework-45-Core"
    Ensure = "Present"
}

xPendingReboot Reboot
{
    Name = "Prior to upgrading Dotnet4.5.2"
}

cChocoPackageInstaller InstallDotNet452
{
    name = "dotnet4.5.2"
}

}
Run Code Online (Sandbox Code Playgroud)

这是一个问题,因为dotnet无法正常使用我们的应用程序,除非服务器已重新启动,我们正在尝试使这些重新启动自动发生,无需用户输入.

是否有任何方法可以将资源推送到localdscmanager(LCM),以便在安装某些内容时需要重新启动?

我找到了以下命令

 $global:DSCMachineStatus = 1 
Run Code Online (Sandbox Code Playgroud)

哪个设置重启.但我不确定如何在安装4.5模块后立即重启它.

Tra*_*z13 6

通常,当我安装.Net时,它可以在不重新启动的情况下工作,但如果您想在安装它之后强制配置重新启动它,您可以执行以下操作.它不适用于漂移(.net在初始安装后被删除.)在配置漂移期间,配置仍将安装.net,但我添加到重新启动的脚本资源将认为它已经重新启动.

DependsOn在这里非常重要,您不希望在WindowsFeature成功运行之前运行此脚本.

configuration WebServer
{
    WindowsFeature NetFramework45Core
    {
        Name = "Net-Framework-45-Core"
        Ensure = "Present"
    }


    Script Reboot
    {
        TestScript = {
            return (Test-Path HKLM:\SOFTWARE\MyMainKey\RebootKey)
        }
        SetScript = {
            New-Item -Path HKLM:\SOFTWARE\MyMainKey\RebootKey -Force
             $global:DSCMachineStatus = 1 

        }
        GetScript = { return @{result = 'result'}}
        DependsOn = '[WindowsFeature]NetFramework45Core'
    }    
}
Run Code Online (Sandbox Code Playgroud)


qbi*_*bik 5

要开始工作,您首先需要在远程节点上$global:DSCMachineStatus = 1配置本地配置管理器以允许自动重新启动。你可以这样做:

Configuration ConfigureRebootOnNode
{
    param (
        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [String]
        $NodeName
    )

    Node $NodeName
    {
        LocalConfigurationManager
        {
            RebootNodeIfNeeded = $true
        }
    }
}

ConfigureRebootOnNode -NodeName myserver 
Set-DscLocalConfigurationManager .\ConfigureRebootOnNode -Wait -Verbose
Run Code Online (Sandbox Code Playgroud)

(代码取自科林的阿尔姆角