Azure Automation State Configuration (PowerShell DSC) & WMI

Hi,

As you know that during the installation of ConfigMgr PRI Site Server, WMI restarts. That is part of the installer which unfortunately cannot be ignored. Is there a way that the target node remains in progress until the installation completes? Basically don’t want the node to show compliant or an error just because of WMI restart.

This thread can be closed as I have found the solution.

@ajaswal Can you share the solution here, so that it will be helpful for someone in future.

Absolutely @kvprasoon !!

As you all know, there are DSC Resources available to setup almost all System Center Products EXCEPT ConfigMgr, I could not really find a working Module or a Custom/Composite Resource in PowerShell Gallery to setup a ConfigMgr Primary Site Server, therefore, for now I created a Script resource.

BTW, this was not really related to WMI restart and I will explain the situation here:

When ConfigMgr starts the installation process, it starts 2 processes together, Setup.exe and SetupWPF.exe. Even if the argument specifies “Setup.exe /Script <Path to the Unattended File> /NoUserInput or /Hidden” (have tried both), it hands over the control to SetupWPF.exe. The SetupWPF.exe exits with a CODE 1 at least twice during the installation process and a new instance of SetupWPF.exe is started along the way, however Setup.exe continues to run. The problem was as soon as SetupWPF.exe was exiting with a CODE 1, Azure Automation State Configuration was treating the Script Resource as DONE which was not the case as the installation was still going on.

Now, the below starts the installation process and SetupWPF.exe is the process recognized which exits with a CODE 1:

 

$pinfo = New-Object System.Diagnostics.ProcessStartInfo

$pinfo.FileName=“\$($Using:Node.NodeName)$($Using:Node.ConfigFolder)$($Using:Node.ConfigMgrSourcePath)$($Using:Node.ConfigMgrExecutablePath)”

$pinfo.RedirectStandardError=$true

$pinfo.RedirectStandardOutput=$true

$pinfo.UseShellExecute=$false

$pinfo.Arguments=“/Script \$($Using:Node.NodeName)$($Using:Node.ConfigFolder)$($Using:Node.UnattendedFileDestinationPath)$($Using:Node.NodeName).TXT /HIDDEN”

$p=New-Object System.Diagnostics.Process

$p.StartInfo=$pinfo

$p.Start() |Out-Null

$p.WaitForExit()

$stdout=$p.StandardOutput.ReadToEnd()

$stderr=$p.StandardError.ReadToEnd()

Write-Verbose-Message “ConfigMgr install stdout: $stdout”

Write-Verbose-Message “ConfigMgr install stderr: $stderr”

Write-Verbose-Message “ConfigMgr install code: $($p.ExitCode)”

What has been added here are some loops and conditions, stating that if there is a Exit CODE 1 from SetupWPF.exe, while Setup.exe is running, keep logging a Verbose Message that "The Setup process is still running". This keeps Azure Automation State Configuration in progress and I can see these messages in the JSON files:
If ($p.ExitCode -eq "1")

{

do {

Start-Sleep-Seconds 5

Write-Verbose-Message “The Setup process is still running”

} while ((Get-Process -Name “Setup” -ErrorAction SilentlyContinue) -ne $Null)

}

After Setup.exe exits, SetupWPF.exe also exits together and after sometime a new process SetupDL.exe starts to do some remaining pieces of work in the installation process. So added a loop again stating that while SetupDL.exe does not start, keep logging a Verbose Message "Waiting for the SetupDL process to start". This also keeps Azure Automation State Configuration in progress and I can see these messages in the JSON files:
While (!(Get-Process "SetupDL" -ErrorAction SilentlyContinue))

{

Start-Sleep-Seconds 5

Write-Verbose-Message “Waiting for the SetupDL process to start”

}

Finally, added another loop and condition stating that if Setup.exe does not exist and SetupDL.exe is running, while SetupDL.exe is running, keep logging a Verbose Message "The SetupDL process has started and is running". And after SetupDL.exe exits which is basically the last line of the log, log a Verbose Message "Configuration Manager is now completely installed". This also keeps Azure Automation State Configuration in progress and I can see these messages in the JSON files and finally, it returns a DONE in Azure Automation State Configuration:
If ((Get-Process -Name "Setup" -ErrorAction SilentlyContinue) -eq $Null -and (Get-Process "SetupDL" -ErrorAction SilentlyContinue) -ne $Null)

{

do {

Start-Sleep-Seconds 5

Write-Verbose-Message “The SetupDL process has started and is running”

} while ((Get-Process -Name “SetupDL” -ErrorAction SilentlyContinue) -ne $Null)

}

Write-Verbose-Message “Configuration Manager is now completely installed”

Hope this helps someone :)

Thanks for sharing it. Please read below instructions to format the code. It will improve the readability for other folks.

https://powershell.org/forums/topic/read-me-before-posting-youll-be-glad-you-did/

Done.