วิธีการเขียน Script ตรวจสอบ Server Performance สำหรับเครื่อง Windows 2008 R2
ขอนำเสนอ Powershell Script สำหรับใช้ Monitor Server Performance สำหรับเครื่อง Windows 2008 R2 ขึ้นไปดังนี้ การติดตั้ง PowerShell Editor และ วิธีใช้งานบน Windows 2008 1. ติดตั้งโดยไปที่ Server Manager -> Features -> Add Features 2. เลือกหัวข้อ Windows PowerShell Integrated Script Environment (ISE) 3. ให้เลือกใช้งาน Version X86 ซึ่งเมื่อลงแล้ว Icon จะอยู่ที่ Accessories -> Windows PowerShell -> Windows PowerShell ISE (x86) คำสั่งในการเปิด Execution Policy Set-ExecutionPolicyUnrestricted -Force การสร้าง Loop เพื่อให้สามารถรันได้ตลอดเวลา While($true){ …..[Monitor Script]….. } คำสั่งตรวจหา IP ของ Server Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object { $_.Description -eq “Intel(R) Dual Band Wireless-N 7260” } | ForEach-Object { $ipaddr = $_.IPAddress } $ip = $ipaddr[0] คำสั่งตรวจสอบ Max CPU Clock Speed Get-WmiObject-class win32_processor -Property “maxclockspeed” | ForEach-Object {$clockspeed = $_.maxclockspeed } Get-WmiObject-class win32_computersystem -Property “NumberOfLogicalProcessors” | ForEach-Object { $lprocessor = $_.NumberOfLogicalProcessors } $sumclockspeed = $clockspeed*$lprocessor คำสั่งตรวจสอบ Current CPU (Get-Counter “\Processor(_Total)\% Processor Time”).CounterSamples | ForEach-Object {$cpuuse = $_.CookedValue} $cpuuse = [math]::round($cpuuse,0) $clockspeed = ($cpuuse*$sumclockspeed)/100 $clockspeed = [math]::round($clockspeed,0) $pcpuuse = $clockspeed/$sumclockspeed $pcpuuse = [math]::round($pcpuuse,0) คำสั่งตรวจสอบ Maximum Memory $sumram = 0 Get-WMIObject-class win32_physicalmemory -Property “Capacity” | ForEach-Object { $sumram = $sumram + $_.Capacity} $sumram = $sumram/(1024*1024) คำสั่งตรวจสอบ Current Memory (Get-Counter “\Memory\Available MBytes”).CounterSamples | ForEach-Object {$memfree = $_.CookedValue} $memuse = $sumram-$memfree; $pmemuse = ($memuse/$sumram)*100 $pmemuse = [math]::round($pmemuse,0) คำสั่งตรวจสอบ Connection $netstat = “netstat