การตรวจสอบกลุ่มแอปพลิเคชันสำหรับ SharePoint โดยใช้สคริปต์ PowerShell
ถ้ากลุ่มแอปพลิเคชัน SharePoint หยุดทำงานซึ่งจะทำให้ "บริการไม่พร้อมใช้งาน" หยุดทำงานในสภาพแวดล้อม SharePoint ของคุณ! แม้ว่า SCOM จะสามารถตรวจสอบสถานะพูลแอปพลิเคชันของแอปพลิเคชันเว็บ SharePoint IIS ได้ แต่จะทำให้มีเสียงรบกวนมากขึ้นเล็กน้อยเมื่อมีการแจ้งเตือน และจะไม่เริ่มกลุ่มแอปพลิเคชันโดยอัตโนมัติเมื่อหยุดทำงาน ดังนั้นเรามาแก้ไขปัญหานี้ด้วยความช่วยเหลือของ PowerShell!
สคริปต์นี้ไม่เพียงสแกนสถานะกลุ่มแอปพลิเคชัน IIS บนเซิร์ฟเวอร์ SharePoint Web-Front เท่านั้น แต่ยังรวมถึง:
- บันทึกสถานะพูลแอปพลิเคชันหากไม่อยู่ในสถานะเริ่มต้น
- เริ่ม AppPool โดยอัตโนมัติหากอยู่ในสถานะหยุดทำงาน
- ส่งอีเมลแจ้งเตือนไปยังทีมผู้ดูแลระบบ SharePoint (หรือใครก็ตามที่กำหนดค่า!)
สคริปต์ PowerShell เพื่อตรวจสอบรูปปั้นพูลแอปพลิเคชัน IIS:
นี่คือสคริปต์ PowerShell ที่ดีของฉันในการตรวจสอบกลุ่มแอปพลิเคชันบนเซิร์ฟเวอร์ส่วนหน้าของเว็บ SharePoint ทั้งหมด
Import-Module WebAdministration
#Array to hold Server names - Change it to YOUR SharePoint front end servers
$WFEServers =("HS-WFE01", "HS-WFE02", "HS-WFE03")
#Log file location
$LogFile = "D:\Scripts\AppPool-Log.txt"
#Loop through each server and Check Application Pool status
foreach ($Server in $WFEServers)
{
$ServerMgr = [Microsoft.Web.Administration.ServerManager]::OpenRemote($Server)
#Get all Application Pools which are not in Started State
$AppPoolColl = $ServerMgr.ApplicationPools | Where-Object {$_.State -ne "Started"}
foreach($AppPool in $AppPoolColl)
{
#Get the time to Log
$now = Get-Date -f "yyyy-MM-dd HH:mm:ss"
#Log to file
"`n Found Application Pool: $($AppPool.name) in stopped state at the server : $($Server) on $($now)" >> $LogFile
"Trying to Start the application Pool...">> $LogFile
#Try Starting the application Pool
$AppPool.Start()
Start-Sleep -s 10
"Application Pool's current Status: $($AppPool.State)" >> $LogFile
#Send Alert-Mail message
$emailFrom = "AppPoolMonitor@crescent.com"
# Use commas for multiple addresses
$emailTo = "SPAdmins@crescent.com"
$subject = "Application Pool: $($AppPool.Name) in stopped state in Server: $($Server) at $($now)"
$body = "Hi SharePoint Team, `n `n The Application Pool $($AppPool.name) was in stopped state in server: $($server). `n`n We tried Re-starting it... Current State of the Application Pool: $($AppPool.State). `n`n Please take necessary actions if its not started !. `n `nThanks, `nSharePoint AppPool Monitoring Script."
$smtpServer = "smtp.crescent.com" #IP or HOST Name of SMTP Server
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)
}
}
นี่คือตัวอย่างการแจ้งเตือนจากสคริปต์ตรวจสอบ IIS AppPool:
กำหนดเวลาสคริปต์ PowerShell นี้ในตัวกำหนดเวลางานของ Windows ในเซิร์ฟเวอร์แอปพลิเคชันใด ๆ (หรือเซิร์ฟเวอร์อื่น ๆ จะทำ!) เพื่อสแกนสถานะกลุ่มแอปเป็นระยะ พูดหนึ่งครั้งต่อ 5 นาที! ช่วงเวลาการทำงานสามารถปรับได้ขึ้นอยู่กับลำดับความสำคัญของแอปพลิเคชันของคุณ
นี่คืออีกโพสต์เกี่ยวกับการกำหนดเวลาสคริปต์ PowerShell โดยใช้ตัวกำหนดเวลางานของ Windows: สร้างงานที่กำหนดเวลาไว้สำหรับสคริปต์ PowerShell ด้วย Windows Task Scheduler
