(用powershell檢測和重啓WINDOWS服務) the powershell script to auto check and restart the qlik services

Background

Its complex and repeatable to stop and start qlik services when in maintain.
So we can write down a powershell script to auto restart the qlik services.

每次qlik服務器有問題的時候,都需要停止和重啓服務,這個時候如果用powershell來處理就很簡單了,三句核心代碼搞定一切.

Script

echo "#####################################################"
echo "  _      __  __    ___   "
echo " | |    |  \/  |  |   \  "
echo " | |__  | |\/| |  | |) | "
echo " |____| |_|  |_|  |___/  "
echo "RESTARTING QLIK SERVICE"
echo "#####################################################"
echo "    by zhengkai.blog.csdn.net"

echo "1.checking qlik services status:"
Get-Service -DisplayName qlik*

echo "2.stopping qlik services"
Get-Service -DisplayName qlik* | Where-Object -FilterScript {$_.CanStop} | Stop-Service

echo "3.starting qlik"
Get-Service -DisplayName qlik* | Where-Object -FilterScript {$_.CanStop} | Start-Service

echo "4.checking qlik services status again"
Get-Service -DisplayName qlik*

Document

The development document that about how to manage the service.can be found in Microsoft's Doc center .
關於如何用PowerShell管理Windows服務,可以參考以下文檔:
https://docs.microsoft.com/zh-cn/powershell/scripting/samples/managing-services?view=powershell-7

  1. 獲取服務
    可以通過使用 Get-Service cmdlet 獲取本地或遠程計算機上的服務。 與使用 Get-Process 相同,使用不帶參數的 Get-Service 命令將返回所有服務。 你可以按名稱進行篩選,甚至可以使用星號作爲通配符:
    PowerShell
PS> Get-Service -Name qlik*


Status   Name               DisplayName                           
------   ----               -----------                           
Running  QlikLoggingService Qlik Logging Service                  
Running  QlikSenseEngine... Qlik Sense Engine Service             
Running  QlikSensePrinti... Qlik Sense Printing Service           
Running  QlikSenseProxyS... Qlik Sense Proxy Service              
Running  QlikSenseReposi... Qlik Sense Repository Database        
Running  QlikSenseReposi... Qlik Sense Repository Service         
Running  QlikSenseSchedu... Qlik Sense Scheduler Service          
Running  QlikSenseServic... Qlik Sense Service Dispatcher   

by zhengkai.blog.csdn.net
  1. 停止、啓動、暫停和重啓服務
    所有 Service cmdlet 都具有相同的一般形式。 可以按公用名或顯示名稱指定服務,並使用列表和通配符作爲值。
    若要停止後臺處理程序,請使用:
    Stop-Service -Name QlikSensePrintingService
    若要在停止後啓動後臺處理程序,請使用:
    Start-Service -Name QlikSensePrintingService
    若要暫停後臺處理程序,請使用:
    Suspend-Service -Name QlikSensePrintingService

  2. 重啓多個服務 可先獲取服務列表,並對其進行篩選,然後執行重啓操作:

PS> Get-Service -Name QlikSense*  | Where-Object -FilterScript {$_.CanStop} | Restart-Service
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章