none
Deploy PowerShell Script on SCCM CB 1902 RRS feed

  • Question

  • The SCCM 2012 has released an update 1706, that has enabled Script Deployment. we have SCCM CB1902 infrastructure and all clients are upgraded with this latest one.  I have created a powershell script which will stop & start certain services and delete software distribution folder on remote machine in order to remediate patch issues. After run a script through SCCM and deployed to an end device. The script works on remote machine but  The script is stuck on "Creating client jobs". Please find below the script and log file from remote machine.

    -------------------------------------------------------------------------------------------------------

    $OSarch = Get-WmiObject -Class Win32_Processor -ComputerName $env:computername | Select-Object AddressWidth

    Write-Host "1. Stopping SMS Service..." 
    Stop-Service -Name CcmExec
    Start-Sleep -Seconds 30

    Write-Host "2. Stopping Windows Update Services..." 
    Stop-Service -Name BITS 
    Stop-Service -Name wuauserv 
    Stop-Service -Name appidsvc 
    Stop-Service -Name cryptsvc 

    Write-Host "3. Deleting Software Distribution and Renaming CatRoot Folder..." 
    Remove-Item $env:systemroot\SoftwareDistribution -Recurse -ErrorAction SilentlyContinue 
    Rename-Item $env:systemroot\System32\Catroot2 catroot2.bak -ErrorAction SilentlyContinue 

    Write-Host "4. Starting Windows Update Services..." 
    Start-Service -Name BITS 
    Start-Service -Name wuauserv 
    Start-Service -Name appidsvc 
    Start-Service -Name cryptsvc 

    Write-Host "5. Starting SMS Services..." 
    Start-Service -Name ccmexec
    Start-Sleep -Seconds 30

    Write-Host "6. Trigger Software Update Evaluation cycle Inventory" 
    $TriggerAction = Invoke-WMIMethod -ComputerName $env:computername -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000108}"

    Write-Host "Process completed!"

    Exit

    ---------------------------------------------------------------------------------

    script.log

    PowerShell path: C:\Windows\system32\WindowsPowerShell\v1.0\PowerShell.exe

    Launching the PowerShell.exe for Script [70296485-C8B1-45E5-ACE4-A3012E122011]

    Creating the task object...

    Executing the task...

    Started script handler job.

    Execution task is kicked off.

    Executing command line: "C:\Windows\system32\WindowsPowerShell\v1.0\PowerShell.exe" -NonInteractive -NoProfile -ExecutionPolicy RemoteSigned -Command "& { . 'C:\Windows\CCM\ScriptStore\70296485-C8B1-45E5-ACE4-A3012E122011_CAB6F34AC0542035DEC6AAF986F6E99C8B793009FF9F92CC7A6F4B91410B6D76.ps1'  | ConvertTo-Json -Compress } " with options (32, 4)

    Redirected system temp folder to 'C:\Windows\CcmTemp'

    Any help and advice would be very much appreciated.

    Thanks,

    Vijay

    Wednesday, July 3, 2019 1:44 PM

All replies

  • Hello Vijay,
     
    I think the reason is that you stop the ccmexec service in the script. "Run script" function relies on it to return the results of the script, so if it is stopped console can't get the running state of the script. 
     
    I have read your codes and it seems there is no need to stop the ccmexec service, stopping other services in the script is enough to remove/rename the two folders safely. It would be better if you could try to remove the commands of stopping/starting ccmexec and check the results again.
     
    Hope my answer could help you and look forward to your feedback.
     
    Best Regards,
    Ray

    Please remembers to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Thursday, July 4, 2019 6:24 AM
  • Hi Ray,

    Thanks for your response.

    Exactly not required to stop ccm service however this script is working on Windows 2008/2012 and windows 7 machines and get status for the script in sccm as well. The script is running on Windows 10 & Windows 2016 server but not providing state messages to SCCM. I have tried finding solutions but none is working.

    Thanks,

    Vijay

    Thursday, July 4, 2019 11:30 AM
  • Have you tried without stopping the ccmexec service?

    Why are you stopping it at all in this script?


    Jason | https://home.configmgrftw.com | @jasonsandys

    Thursday, July 4, 2019 4:09 PM
  • Hello,
     
    I notice that you have not updated for several days. Has your issue been solved? Or is there any update? Have you tried without stopping the ccmexec service?
     
    Feel free to feedback.
     
    Best Regards,
    Ray

    Please remembers to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Monday, July 8, 2019 12:34 PM
  • Let me remove stopping ccmexec service line and try it today and update you.

    Thanks,

    Vijay

    Tuesday, July 9, 2019 11:38 AM
  • Hi Ray,

    I removed the line to stop/start ccmexec service from script and ran into windows 10 & 2016 machines. It works as expected and received state messages in SCCM as well.

    Thanks for your timely help!

    Regards,

    Vijay

    Tuesday, July 9, 2019 1:16 PM
  • Hello, 

    Glad to hear it works. It would be very helpful if you could mark it as answer so it would help others having similar issues.

    Best regards, 

    Ray


    Please remembers to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Tuesday, July 9, 2019 2:07 PM