PowerShell — Windows Services & Ops Audit
Windows Server · PowerShell
Executive Summary (EN): Read-only Windows Server PowerShell audit checklist covering service health and WinRM readiness (
Get-Service), installed hotfix verification (Get-HotFix), uptime and 24-hour System Event Log error triage (Get-WinEvent), plus-WhatIfsafe-change guardrails.Operational Note: Sanitized enterprise reference runbook — validate in a staging/lab environment before production execution. คำสั่งในส่วนนี้ออกแบบมาเพื่อตรวจสอบสถานะ Service, WinRM, Patch level และ Event Log โดยไม่เปลี่ยนแปลงการตั้งค่าของเครื่อง
1. ตรวจสอบ Windows Services
# แสดงรายการ Service ทั้งหมด
Get-Service
# ตรวจสอบสถานะ WinRM สำหรับ Remote Management
Get-Service -Name WinRM
# กรองเฉพาะ Service ที่กำลังทำงานอยู่
Get-Service | Where-Object Status -eq 'Running'
# ตรวจสอบ Service ที่ตั้งค่าเป็น Automatic แต่ยังไม่ทำงาน (ตรวจสอบหลัง Reboot/Patch)
Get-Service | Where-Object { $_.StartType -eq 'Automatic' -and $_.Status -ne 'Running' } |
Select-Object Name, DisplayName, Status, StartType2. ตรวจสอบ Patch Level (Windows Update Audit)
# แสดง Patch/HotFix ล่าสุดเรียงตามวันที่ติดตั้ง
Get-HotFix |
Select-Object HotFixID, Description, InstalledOn |
Sort-Object InstalledOn -Descending |
Select-Object -First 153. ตรวจสอบ System Uptime & Event Log เบื้องต้น
# ตรวจสอบเวลา Boot ล่าสุดและ Uptime
(Get-CimInstance Win32_OperatingSystem) |
Select-Object CSName, Caption, LastBootUpTime
# ดู Error ใน System Event Log ย้อนหลัง 24 ชั่วโมงล่าสุด
Get-WinEvent -FilterHashtable @{
LogName = 'System'
Level = 2
StartTime = (Get-Date).AddDays(-1)
} -MaxEvents 25 | Select-Object TimeCreated, Id, ProviderName, Message4. Safe Change Checklist
ก่อน Restart หรือปรับ Service ใดๆ บน Production Server:
- ยืนยัน Change Ticket และผลกระทบต่อ Dependent Services ด้วย
Get-Service -Name <ServiceName> -DependentServices - ทดสอบ Dry-Run ด้วย
-WhatIfเสมอก่อนรันคำสั่งที่เปลี่ยนแปลงสถานะ เช่น:
Restart-Service -Name Spooler -WhatIf- ตรวจสอบ Service Health และ Event Log หลัง Maintenance เสร็จสิ้น