2
0
Files
TacticalRMM_Scripts/Check_scripts/Win - Automatic Services and remidiation.ps1

60 lines
2.0 KiB
PowerShell

<#
.SYNOPSIS
Check all Windows Services with automatic startup type.
.DESCRIPTION
This script will check all services on a machine that are configured with the automatic startup type,
This script should be deployed as a Check Script.
The first Variable in the script are explusion service names that won't be checked. Adjust this acording tot he environment.
.OUTPUTS
This script will check all services under a Windows machine with the startup type "Automatic starting".
Errorcodes:
0 - All OK
1 - Automatic Services are stopped and cannot be started automatically
.EXAMPLE
Win - Automatic Services and remidiation.ps1
.NOTES
Author: D.de Kooker <info@dcomputers.nl>
Source: n/a
.CHANGELOG
24-06-2022 - Initial script.
26-06-2022 - Added remediation to start stopped services
03-02-2025 - Changed the services lookup to allow wildcards
#>
#region Parameters, functions and global variables
$VAR_Excludes = @("edgeupdate","RemoteRegistry","sppsvc","MapsBroker","gupdate","TrustedInstaller","GoogleUpdater*")
$Services = Get-Service | Where-Object {
($_.Name -notmatch ($VAR_Excludes -join "|")) -and
($_.StartType -eq "Automatic") -and
($_.Status -ne "Running")
}
#endregion
#region script
if (!($Services)) {
Write-Output "No Stopped automatic services found"
exit 0
}
Else {
Write-Output "Some automatic services are stopped"
$Services
Write-Output "Trying to start stopped services"
foreach ($Service in $Services) {
Write-Output "Starting service $($Service.Name)..."
Start-Service -Name $Service.Name -ErrorAction Continue
}
$Services = Get-Service | Where-Object { $_.Name -notin $VAR_Excludes -and $_.StartType -eq "Automatic" -and $_.Status -ne "Running" }
if (!($Services)) {
Write-Output "No more stopped automatic services found"
exit 0
}
exit 1
}
#endregion