From af15ba1aec8ed0416586d3ed43338471f2d20c85 Mon Sep 17 00:00:00 2001 From: Danny de Kooker Date: Wed, 6 Sep 2023 15:36:37 +0200 Subject: [PATCH] Add Check_scripts/Win - Automatic Services and remidiation.ps1 --- ...n - Automatic Services and remidiation.ps1 | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Check_scripts/Win - Automatic Services and remidiation.ps1 diff --git a/Check_scripts/Win - Automatic Services and remidiation.ps1 b/Check_scripts/Win - Automatic Services and remidiation.ps1 new file mode 100644 index 0000000..d51efa8 --- /dev/null +++ b/Check_scripts/Win - Automatic Services and remidiation.ps1 @@ -0,0 +1,54 @@ +<# + .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 + Source: n/a + + .CHANGELOG + 24-06-2022 - Initial script. + 26-06-2022 - Added remediation to start stopped services +#> + +#region Parameters, functions and global variables + $VAR_Excludes = "edgeupdate","RemoteRegistry","sppsvc","MapsBroker","gupdate","TrustedInstaller" + $Services = Get-Service | Where-Object { $_.Name -notin $VAR_Excludes -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 \ No newline at end of file