Test-PleskWindowsServices.ps1
|
<#PSScriptInfo .VERSION 1.0.0 .GUID 41365ecb-59c9-4885-b560-af402d996cdf .AUTHOR iServerSupport .COMPANYNAME iServerSupport .COPYRIGHT .TAGS Plesk IIS WindowsServer PowerShell Monitoring SysAdmin .LICENSEURI .PROJECTURI https://iserversupport.com/plesk-server-management/ .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES Initial release. Checks IIS W3SVC, WAS, and Plesk Management Service status. .PRIVATEDATA #> <# .DESCRIPTION Checks IIS and Plesk Windows service status on Windows Server. #> <# .SYNOPSIS Checks IIS and Plesk service status on Windows Server. .DESCRIPTION Performs a read-only health check of IIS and Plesk services. The script checks: - W3SVC - IIS World Wide Web Publishing Service - WAS - Windows Process Activation Service - plesksrv - Plesk Management Service This script must be executed on a Windows Server for service checks. Exit codes: 0 = All required services are running 1 = One or more services are stopped or missing 2 = Operating system is not Windows .EXAMPLE .\Test-PleskWindowsServices.ps1 .NOTES Requires PowerShell 5.1 or PowerShell 7+ Designed for Plesk Obsidian on Windows Server. #> [CmdletBinding()] param() $ErrorActionPreference = 'Stop' Write-Host "" Write-Host "IIS / Plesk Service Health Check" -ForegroundColor Cyan Write-Host "---------------------------------" -ForegroundColor Cyan Write-Host "" # Make sure the script is running on Windows if ($env:OS -ne "Windows_NT") { Write-Host "[INFO] This script is designed for Windows Server." ` -ForegroundColor Yellow Write-Host "[INFO] IIS and Plesk Windows services cannot be checked from macOS/Linux." ` -ForegroundColor Yellow Write-Host "" Write-Host "Run this script on the Windows Server hosting Plesk." ` -ForegroundColor Yellow exit 2 } $servicesToCheck = @( @{ Name = "W3SVC" Description = "IIS World Wide Web Publishing Service" }, @{ Name = "WAS" Description = "Windows Process Activation Service" }, @{ Name = "plesksrv" Description = "Plesk Management Service" } ) $failed = $false foreach ($item in $servicesToCheck) { try { $service = Get-Service ` -Name $item.Name ` -ErrorAction Stop if ($service.Status -eq "Running") { Write-Host ( "[ OK ] {0,-10} {1}" -f $service.Name, $item.Description ) -ForegroundColor Green } else { Write-Host ( "[FAIL] {0,-10} {1} - Status: {2}" -f $service.Name, $item.Description, $service.Status ) -ForegroundColor Red $failed = $true } } catch [System.InvalidOperationException] { Write-Host ( "[MISS] {0,-10} {1} - Service not found" -f $item.Name, $item.Description ) -ForegroundColor Yellow $failed = $true } catch { Write-Host ( "[ERR ] {0,-10} {1} - {2}" -f $item.Name, $item.Description, $_.Exception.Message ) -ForegroundColor Red $failed = $true } } Write-Host "" if ($failed) { Write-Host ` "Result: One or more required services need attention." ` -ForegroundColor Red exit 1 } Write-Host ` "Result: IIS and Plesk services are running." ` -ForegroundColor Green exit 0 |