Forum Discussion
AB21805
Jan 12, 2023Bronze Contributor
How do I restart a service - via intune
Hi all, The service wildsvc has stopped on some machines and I need it to be running so that I can make sure my update features are getting deployed to the devices. Is there a way through in...
RGijsbersRademakers
Jan 12, 2023Iron Contributor
Hi A, Depending on your license, you could make use of proactive remediations. You can create a detection script which will check if the service is running. If that's not the case, the remediation script will kick in which starts the service. More info can be found here: https://learn.microsoft.com/en-us/mem/analytics/proactive-remediations If you don't have the required licences, you could create a custom powershell script which deploys a scheduled task that regularly checks the service and starts the service if it's stopped. Regards, Ruud
AB21805
Jan 12, 2023Bronze Contributor
Hi, I do have the license, what would the scripts look like?
Thanks in advanced
Thanks in advanced
- RGijsbersRademakersJan 12, 2023Iron ContributorA few examples can be found here: https://learn.microsoft.com/en-us/mem/analytics/powershell-scripts
In the try sections, you would put something like
$result = Get-Service wildsvc
If ( $result.status -eq stopped){
Write-Host "Match"
Exit 1}
Else {
Exit 0 }
The remediation script would then contain a Start-Service wildsvc
Regards,
Ruud- AB21805Jan 12, 2023Bronze ContributorHi Ruud,
So would the remediation script look like this:
$result = Start-Service wildsvc
If ( $result.status -eq stopped){
Write-Host "Match"
Exit 1}
Else {
Exit 0 }- RGijsbersRademakersJan 12, 2023Iron Contributor
Hi AB21805 ,
Your detection script would look like this:
#============================================================================================================================= # # Script Name: Detect_Stopped_Services.ps1 # Description: Detect stopped service #============================================================================================================================= # Define Variables $results = @() try { $results = Get-Service wildsvc if (($results.status -eq "Stopped")){ #Below necessary for Intune as of 10/2019 will only remediate Exit Code 1 Write-Host "Match" exit 1 } else{ #Service is still running Write-Host "No_Match" exit 0 } } catch{ $errMsg = $_.Exception.Message Write-Error $errMsg exit 1 }
Your remediation script would look like this:
#============================================================================================================================= # # Script Name: Remediate_Stopped_Service.ps1 # Description: Start the stopped Service #============================================================================================================================= try { Start-Service wildsvc exit 0 } catch{ $errMsg = $_.Exception.Message Write-Error $errMsg exit 1 }
Regards,
Ruud
- Jan 12, 2023You could always ask chatgpt to write you a script to restart a service when it was stopped ? 🙂 but there is even a build in one.... to restart the office c2r service
https://www.anoopcnair.com/deploy-proactive-remediation-script-intune/- AB21805Jan 12, 2023Bronze ContributorHi Rudy,
I need to restart the wlidsvc service or does Office c2r service also include the wlidsvc service?