Issue
Code backup
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
##########################
|
||||
# Writer: Claudio Boggian
|
||||
# Company: PAL s.r.l.
|
||||
#-------------------------
|
||||
# Date: 2023/08/25
|
||||
# v: 1.0
|
||||
# Reason: Emission
|
||||
#-------------------------
|
||||
##########################
|
||||
|
||||
$Services = Get-WmiObject win32_service -Filter "startmode = 'auto' AND state != 'running'"
|
||||
|
||||
$i = 0
|
||||
$objs = $null
|
||||
|
||||
if ($Services){
|
||||
foreach ($Service in $Services) {
|
||||
# Exclude Triggered
|
||||
if(!(Test-Path -Path "HKLM:\SYSTEM\CurrentControlSet\Services\$($Service.Name)\TriggerInfo\"))
|
||||
{
|
||||
$i++
|
||||
|
||||
$objs += @(New-Object -TypeName PSObject -Property @{
|
||||
|
||||
Name = $Service.Name
|
||||
Status = $Service.State
|
||||
StartMode = $Service.StartMode
|
||||
} | Select-Object Name, Status, StartMode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($i -ne 0){
|
||||
Write-Output "$($i) Services is not running!"
|
||||
|
||||
Write-Output $objs
|
||||
|
||||
$exitcode = 2
|
||||
} else {
|
||||
Write-Output "All Services are up and running!"
|
||||
$exitcode = 0
|
||||
}
|
||||
|
||||
exit $exitcode
|
||||
@@ -0,0 +1,38 @@
|
||||
##########################
|
||||
# Writer: Claudio Boggian
|
||||
# Company: PAL s.r.l.
|
||||
#-------------------------
|
||||
# Date: 2023/08/25
|
||||
# v: 1.0
|
||||
# Reason: Emission
|
||||
#-------------------------
|
||||
##########################
|
||||
|
||||
$exclusions=$args[0]
|
||||
|
||||
$tempServices = Get-Service | Where-Object { `
|
||||
($_.starttype -eq 'Automatic') `
|
||||
-and ($_.status -ne 'Running') `
|
||||
-and ($exclusions.split(',') -notcontains $_.name)
|
||||
}
|
||||
|
||||
$Services = @()
|
||||
if ($tempServices){
|
||||
foreach ($Service in $tempServices) {
|
||||
# Exclude Triggered
|
||||
if(!(Test-Path -Path "HKLM:\SYSTEM\CurrentControlSet\Services\$($Service.Name)\TriggerInfo\"))
|
||||
{
|
||||
$Services += $Service | Select-Object name, displayname, status
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$exitState = 0
|
||||
if ($Services.Count -gt 0){
|
||||
Write-Output "CRITICAL - $($Services.Count) Services are not running!"
|
||||
Write-Output $Services
|
||||
$exitState = 2
|
||||
} else {
|
||||
Write-Output "OK - All Services are up and running!"
|
||||
}
|
||||
exit $exitState
|
||||
Reference in New Issue
Block a user