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:
- A VM is successfully deployed as a nested (linked) template
- Next, again as a nested (linked) template dependent on the VM deployment, a Powershell DSC extension template is created
- Within the Powershell DSC configuration a reboot should be forced at a certain stage
- Tried two scenarios: a) using VM with Windows Server 2016 Datacenter and b) Windows Server 2012
- 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.
- 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....