วิธีใช้ PowerShell ตรวจสอบสถานะ Windows Server 2022 แบบมืออาชีพ

 PowerShell เป็นเครื่องมือที่ทรงพลังที่สุดสำหรับผู้ดูแลระบบ Windows Server 2022 เพราะสามารถตรวจสอบสถานะของระบบได้แทบทุกส่วน ไม่ว่าจะเป็น CPU, RAM, Disk, Network, Services, Event Logs, Active Directory หรือ Windows Update

องค์กรขนาดใหญ่จำนวนมากใช้ PowerShell ในการทำ Health Check และ Automation แทนการตรวจสอบแบบ Manual เพราะรวดเร็ว แม่นยำ และสามารถตรวจสอบ Server หลายเครื่องพร้อมกันได้

บทความนี้จะรวบรวมคำสั่ง PowerShell สำคัญสำหรับตรวจสอบสถานะ Windows Server 2022 ที่ผู้ดูแลระบบควรรู้

🔹 ทำไมต้องใช้ PowerShell

ข้อดี

✅ รวดเร็ว

✅ ทำงานอัตโนมัติได้

✅ ตรวจสอบหลายเครื่องพร้อมกัน

✅ ส่งออกข้อมูลเป็น Report ได้

✅ ใช้ร่วมกับ Monitoring System ได้

🔹 ตรวจสอบข้อมูลระบบ

ดูข้อมูล Windows Server 2022

Get-ComputerInfo

ดูชื่อเครื่อง

hostname

ดูเวอร์ชัน Windows

systeminfo

🔹 ตรวจสอบ Uptime

ดูระยะเวลาที่เครื่องเปิดทำงาน

(Get-Date) - (gcim Win32_OperatingSystem).LastBootUpTime

ช่วยวางแผน Maintenance ได้

🔹 ตรวจสอบ CPU

ดูโหลด CPU

Get-Counter "\Processor(_Total)\% Processor Time"

🔹 ดู Process ใช้ CPU สูงสุด

Get-Process | Sort CPU -Descending | Select -First 10

🔹 ตรวจสอบ RAM

ดู RAM ทั้งหมด

Get-CimInstance Win32_ComputerSystem

ดู RAM คงเหลือ

Get-Counter "\Memory\Available MBytes"

🔹 ตรวจสอบ Process ใช้ RAM สูง

Get-Process | Sort WorkingSet -Descending | Select -First 10

🔹 ตรวจสอบ Disk

ดูดิสก์ทั้งหมด

Get-Disk

🔹 ตรวจสอบพื้นที่ว่าง

Get-Volume

ดู

✅ Drive Letter

✅ Free Space

✅ Total Size

🔹 ตรวจสอบ Storage Health

Get-PhysicalDisk

สถานะควรเป็น

Healthy

🔹 ตรวจสอบ Network

ดูการ์ดเครือข่าย

Get-NetAdapter

🔹 ดู IP Address

Get-NetIPAddress

🔹 ตรวจสอบ Default Gateway

Get-NetRoute

🔹 ทดสอบการเชื่อมต่อ

Test-NetConnection google.com

🔹 ตรวจสอบ DNS

Resolve-DnsName google.com

🔹 ตรวจสอบ Services

ดู Service ทั้งหมด

Get-Service

🔹 ดู Service ที่หยุดทำงาน

Get-Service | Where-Object {$_.Status -eq "Stopped"}

🔹 ตรวจสอบ Event Logs

ดู Error ล่าสุด

Get-EventLog -LogName System -Newest 20

🔹 ดู Critical Events

Get-WinEvent -FilterHashtable @{Level=1}

🔹 ตรวจสอบ Windows Update

ดูรายการ Update

Get-HotFix

🔹 ดูวันที่ติดตั้งล่าสุด

Get-HotFix | Sort InstalledOn

🔹 ตรวจสอบ Active Directory

หากเป็น Domain Controller

dcdiag

🔹 ตรวจสอบ DNS

ดู Service DNS

Get-Service DNS

🔹 ตรวจสอบ DHCP

Get-DhcpServerv4Scope

🔹 ตรวจสอบ IIS

ดู Website

Get-Website

🔹 ตรวจสอบ Application Pool

Get-WebAppPoolState

🔹 ตรวจสอบ Hyper-V

ดู VM ทั้งหมด

Get-VM

🔹 ตรวจสอบสถานะ VM

Get-VM | Select Name,State

🔹 ตรวจสอบ Firewall

Get-NetFirewallProfile

🔹 ตรวจสอบ User Login

ดู Session ปัจจุบัน

quser

🔹 ตรวจสอบ Reboot Pending

Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing

🔹 สร้าง Health Check Script

สามารถรวมคำสั่งทั้งหมด

แล้วส่งออกเป็น

HTML
CSV

หรือ

TXT

ได้

🔹 ตรวจสอบหลายเครื่องพร้อมกัน

ตัวอย่าง

Invoke-Command

ช่วยลดเวลาทำงานอย่างมาก

🔹 ใช้ Scheduled Task

ให้ Script ทำงานอัตโนมัติ

ทุกวัน

แล้วส่งผลทาง Email

ได้ทันที

🔹 ตัวอย่างข้อมูลที่ควรเก็บ

✅ CPU

✅ RAM

✅ Disk

✅ Network

✅ Event Logs

✅ Services

ทุกวัน

🔹 แนวทางสำหรับองค์กร

องค์กรที่ทีมงาน comsiam ดูแลจะใช้ PowerShell Automation บน Windows Server 2022 เพื่อสร้างรายงานสุขภาพระบบอัตโนมัติและตรวจจับปัญหาก่อนเกิด Downtime

🔹 Best Practices

✅ ใช้ PowerShell ทุกวัน

✅ ทำ Automation

✅ ส่งออก Report

✅ ตรวจสอบ Error Logs

✅ ใช้ร่วมกับ Monitoring Tools

✅ เก็บข้อมูลย้อนหลัง

🔹 Checklist PowerShell Health Check

✅ CPU ปกติ

✅ RAM ปกติ

✅ Disk ปกติ

✅ Network ปกติ

✅ Services ทำงานครบ

✅ ไม่มี Critical Error

🔹 สรุป

PowerShell เป็นเครื่องมือสำคัญสำหรับการตรวจสอบสถานะ Windows Server 2022 เพราะสามารถเข้าถึงข้อมูลของระบบได้แทบทุกส่วน และสามารถนำไปสร้าง Automation ได้อย่างมีประสิทธิภาพ

การใช้ PowerShell เพื่อตรวจสอบ CPU, RAM, Disk, Network, Services และ Event Logs อย่างสม่ำเสมอ จะช่วยให้ผู้ดูแลระบบสามารถค้นหาปัญหาได้รวดเร็ว ลด Downtime และเพิ่มเสถียรภาพของ Windows Server 2022 ซึ่งเป็นแนวทางที่ทีมงาน comsiam ใช้งานจริงในองค์กรขนาดใหญ่

Popular posts from this blog

Windows Server 2022 ยังน่าใช้ในปีนี้หรือไม่? คำตอบสำหรับคนกำลังวางระบบใหม่

สเปกเครื่องสำหรับติดตั้ง Windows Server 2022 เลือกอย่างไรให้คุ้มและใช้งานได้ยาว

Windows Server 2022 คืออะไร? คู่มือสำหรับมือใหม่