title: SCCM Compliance state always 'Compliant' when remediation script runs
body: <p>We're trying to use SCCM 2012 R2 to run some checks on clients and fix problems when needed. For this we use the PowerShell 'Script' option.</p>
  
  <p><strong>Problem description:</strong></p>
  
  <p>When a 'Discovery script' reports ‘Non-Compliant’ the ‘Remediation script’ is launched. Regardless of the output of the ‘Remediation script’, the result in the report on the client in ‘Configuration Manager > Configurations’ is always ‘Compliant’ even when the ‘Remediation script’ failed to fix the issue and as a result has different output then defined in the ‘Rules for compliance conditions’.</p>
  
  <p>It seems that from the moment a ‘Remediation script’ is selected, the output of the SCCM Compliance State is always ‘Compliant’.</p>
  
  <p><strong>Example:</strong></p>
  
  <p><strong>- Situation:</strong></p>
  
  <p>When there are files or folders in the folder ‘C:\Users\me\Downloads\Input_Test’ the ‘Discovery script’ reports ‘Not compliant to anything’ and kicks of the ‘Remediation script’. The remediation script takes action and can’t fix the problem so it reports back something else then ‘Compliant’, like ‘Non-Compliant’. The SCCM Compliance State should say after execution of the ‘Remediation script’: ‘Non-Compliant’ (which is not the case).</p>
  
  <p><strong>- PowerShell Discovery script:</strong></p>
  
  <pre><code>$Paths = Get-ChildItem -Path 'C:\Users\me\Downloads\Input_Test' | Select -ExpandProperty FullName
  New-EventLog -LogName Application -Source SCCMCompliance
  if ($Paths) {
      $Compliance = 'Non-Compliant'
      Write-EventLog -LogName Application -Source SCCMCompliance -EntryType Warning -EventID 1 -Message “Discovery script: Non-Compliant”
  }
  else {
      $Compliance = 'Compliant'
      Write-EventLog -LogName Application -Source SCCMCompliance -EntryType Information -EventID 0 -Message “Discovery script: Compliant”
  }
  $Compliance 
  </code></pre>
  
  <p><strong>- PowerShell Remediation script:</strong></p>
  
  <pre><code>Write-Output 'Non-Compliant'
  Write-EventLog -LogName Application -Source SCCMCompliance -EntryType Warning -EventID 1 -Message “Remediation script: Non-Compliant $Paths” 
  </code></pre>
  
  <p><strong>- SCCM Rules for compliance conditions:</strong>
   <a href="https://i.stack.imgur.com/RaVGm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RaVGm.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/PpDYt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PpDYt.png" alt="enter image description here"></a></p>
  
  <p><strong>- SCCM Compliance State in the Configuration Manager:</strong>
   <a href="https://i.stack.imgur.com/5cegj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5cegj.png" alt="enter image description here"></a></p>
  
  <p>In the Windows event viewer all steps can be tracked easily. Am I missing something super obvious here?</p>