0

I'm struggling with configuring a Reboot through Powershell DSC. This is my scenario:

Using Azure RM Template deployments with a Visual Studio 2017 Resource Group project:

  1. A VM is successfully deployed as a nested (linked) template
  2. Next, again as a nested (linked) template dependent on the VM deployment, a Powershell DSC extension template is created
  3. Within the Powershell DSC configuration a reboot should be forced at a certain stage
  4. Tried two scenarios: a) using VM with Windows Server 2016 Datacenter and b) Windows Server 2012
  5. Both scenarios report a failure. a) The first one fails at the reboot. b) The second one however seems to reboot and finish with the configurations, but still a failure is reported on the resource group deployments and VS output.
  6. In both scenarios the error is: "DSC Configuration 'Main' completed with error(s). Following are the first few: C A general error occurred that is not covered by a more specific error code. C"

Here is the DSC configuration:

Configuration Main
{

param(
    ... a few parameters here ...
)

### required only for Windows Server 2012
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process -Force
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser -Force
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope LocalMachine -Force
###


Import-DscResource -ModuleName PSDesiredStateConfiguration
Import-DscResource -ModuleName xPendingReboot

Node "localhost"
{
    LocalConfigurationManager
    {
        RebootNodeIfNeeded = $true
    }

    ... Initial Configuration ...

    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 = 'Reboot'}}
        DependsOn = '<Initial Configuration>'
    } 
    # Reboot if pending
    xPendingReboot RebootCheck
    {
        Name = "RebootCheck"
    }

    ... Configuration Continued ...
}
}

Any help would be appreciated, thanks!

SOME UPDATE:

Actually, my "reboot" requirement is a workaround, because when the two deployments are executed as nested templates one after the other - the Powershell DSC fails (if I deploy them separately, everything works fine). The configuration seems to fail after a Script Resource has installed a windows service using NSSM. Then I noticed that if a restart is initiated on the machine, the configuration is applied successfully. Thus, the workaround with a restart....

Vladislav
  • 2,772
  • 1
  • 23
  • 42
  • 1
    can you check the logs? I can say for sure this scenario works for my dsc configurations – 4c74356b41 Oct 15 '18 at 10:51
  • The logs report a NativeCommandErrorMessage that seems to be connected with a Script Resource from the "initial configuration". The error is described as a "non-terminating". Still something strange, though: the VM did restart only a few minutes after I remotely logged into it, however my custom logs show that the "configuration continued" has been executed... I somehow expected that `xPendingReboot` will immediately stop the configuration process – Vladislav Oct 15 '18 at 11:54
  • 1
    i think you need to add `DependsOn = "[xPendingReboot]RebootCheck"` to all resources after xPendingReboot one – 4c74356b41 Oct 15 '18 at 12:11
  • yes I have chained them with the first one dependent on xPendingReboot. And just to remind that on Windows Server 2016 Datacenter the restart is not happening at all. I guess something has changed on that version, because here it is not confirmed to work: https://gallery.technet.microsoft.com/scriptcenter/xPendingReboot-PowerShell-b269f154 – Vladislav Oct 15 '18 at 12:17
  • 1
    i'm using xpendingreboot on 2016 vms without any issues – 4c74356b41 Oct 15 '18 at 12:19
  • in terms of rebooting, do you think that I have configured everything that is required? IF so, then it should be the other configuration that messes things up... – Vladislav Oct 15 '18 at 12:25
  • 1
    looks okaish to me, check my working example: https://github.com/AvyanConsultingCorp/PCI_Reference_Architecture/blob/master/artifacts/configurationscripts/ad-domain.ps1 – 4c74356b41 Oct 15 '18 at 13:01
  • did it work for you? – 4c74356b41 Oct 26 '18 at 11:34
  • yes, eventually it turned out that the reboot is fine, thanks! – Vladislav Oct 26 '18 at 12:07

1 Answers1

0

in this case the solution was to add:

DependsOn = "[xPendingReboot]RebootCheck"

to all resources after xPendingReboot

4c74356b41
  • 69,186
  • 6
  • 100
  • 141