Skip to content

Commit a11bce0

Browse files
author
Alexei Andreyev
committed
Merge pull request #47 from nick-o/issue/45
Adding additional criteria for rerunning Consistency task
2 parents 92169af + 1355b37 commit a11bce0

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

rsBasePrep.ps1

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,24 @@ Function Install-DSC {
153153
powershell.exe certutil -addstore -f root $("C:\DevOps", $d.mR, "Certificates\PullServer.crt" -join '\')
154154
$i = 0
155155
do {
156-
if ( $((Get-WinEvent Microsoft-Windows-DSC/Operational | Select -First 1).id) -eq "4104" ) {
156+
$StartConsistency = $false
157+
$Pending = Test-Path "C:\Windows\System32\Configuration\Pending.mof"
158+
$ConsistencyRunning = (Get-ScheduledTask -TaskName Consistency).State -eq "Running"
159+
if ( $((Get-WinEvent Microsoft-Windows-DSC/Operational | Select -First 1).id) -eq "4104" -or
160+
($Pending -and (-not $ConsistencyRunning))) {
157161
Get-ScheduledTask -TaskName "Consistency" | Start-ScheduledTask
162+
if ($Pending -and (-not $ConsistencyRunning))
163+
{
164+
$StartConsistency = $true
165+
}
158166
}
159-
if($i -gt 5) {
160-
Write-EventLog -LogName DevOps -Source BasePrep -EntryType Information -EventId 1000 -Message "Waiting for Client to install DSC configuration"
167+
if($i -gt 5 -or $StartConsistency) {
168+
$Message = "Waiting for Client to install DSC configuration"
169+
if ($StartConsistency)
170+
{
171+
$Message += "`nFound Pending.mof and Consistency task not running and therefore started Consistency Task"
172+
}
173+
Write-EventLog -LogName DevOps -Source BasePrep -EntryType Information -EventId 1000 -Message $Message
161174
$i = 0
162175
}
163176
$i++

0 commit comments

Comments
 (0)