Add Check_scripts/Win - Automatic Services and remidiation.ps1
This commit is contained in:
54
Check_scripts/Win - Automatic Services and remidiation.ps1
Normal file
54
Check_scripts/Win - Automatic Services and remidiation.ps1
Normal file
@@ -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 <info@dcomputers.nl>
|
||||||
|
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
|
||||||
Reference in New Issue
Block a user