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...
AB21805
Jan 12, 2023Bronze Contributor
Hi, I do have the license, what would the scripts look like?
Thanks in advanced
Thanks in advanced
RGijsbersRademakers
Jan 12, 2023Iron Contributor
A 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
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
- Maharram_NajafovJun 24, 2024Copper Contributorhow do we directly run ps1 file via intune? I want to stop the DLP service and destroy it.