none
SCCM 2012 SP1 DCM Auto Remediation RRS feed

  • Question

  • Hi Guys

    I have the following 2 scripts which check the status of for example the "Spooler" service and if not "Running" then it will return a "Non-Compliant" for the DCM, my problem is the Auto Remediation  script.

    Here are the 2 PowerShell scripts

    Discovery

    $servicestatus=get-service | select status,name | Where-Object {$_.Name -like  "spooler"}$ServiceStatus=($servicestatus.status)$ServiceStatus

    Remediation

    param($ServiceStatus) $arrService = get-service | select status,name | Where-Object {$_.Name -like  "spooler"} if ($arrService.Status -eq $ServiceStatus){ Start-Service 'Spooler' }

    Now the "Discovery script works fine and when the service state is "Stopped" then a "Non-Compliance" is raised, now I also know that the "Remediation" script is passed the Non-Compliant value as a parameter.

    So could someone please let me know if my second script is correct or if i am missing something as the "Remediation" is not working when "Non-Compliant" is raised

    Thank you

    Tuesday, September 3, 2013 1:11 PM

Answers

  • Hi

    I have managed to fix it, all i did was use the following as my Remediation script and it works perfectly and starts the service automatically.

    start-service -name 'spooler'
    Thank you


    • Marked as answer by Leonya1 Tuesday, September 3, 2013 6:31 PM
    Tuesday, September 3, 2013 6:31 PM

All replies

  • Your remediation powershell is incorrect.  You've got an "if" in your Where-Object command which is not supported. If you are trying to use an "if" statement, see get-help about-if for usage.


    Nash Pherson, Senior Systems Consultant
    Now Micro - My Blog Posts
    <-- If this post was helpful, please click "Vote as Helpful".


    • Edited by NPherson Tuesday, September 3, 2013 3:47 PM clarification
    Tuesday, September 3, 2013 3:46 PM
  • Hi

    Thanks for the reply, i have changed both to the following

    Discovery

    $servicestatus=get-service -Name "Spooler"$ServiceStatus=($servicestatus.status)$ServiceStatus


    Remediation

    param($ServiceStatus) $arrService = Get-Service -Name 'Spooler' if ($arrService -eq $ServiceStatus){ Start-Service 'Spooler' }
     

    but I get the following now and it doesn't start the service

    It says it has "Remediated" but the service inst running

    Tuesday, September 3, 2013 4:15 PM
  • Hi

    I have managed to fix it, all i did was use the following as my Remediation script and it works perfectly and starts the service automatically.

    start-service -name 'spooler'
    Thank you


    • Marked as answer by Leonya1 Tuesday, September 3, 2013 6:31 PM
    Tuesday, September 3, 2013 6:31 PM
  • Simple is always best!

    Nash


    Nash Pherson, Senior Systems Consultant
    Now Micro - My Blog Posts
    <-- If this post was helpful, please click "Vote as Helpful".

    Tuesday, September 3, 2013 6:33 PM