天天看點

設定Windows計劃任務定期執行PowerShell腳本

因PowerShel有這特殊的安全政策,在設定Windows計劃任務定期執行PowerShell腳本時有些細節需要注意。

(1)在本機編寫一個測試腳本,儲存為PS1腳本;

<a href="http://281816327.blog.51cto.com/attachment/201407/10/907015_1404978002zLNE.png" target="_blank"></a>

(2)設定Powershell執行政策為RemoteSigned;

<a href="http://281816327.blog.51cto.com/attachment/201407/10/907015_1404978004ARUE.png" target="_blank"></a>

(3)在伺服器管理器中建立一個基本任務;

<a href="http://281816327.blog.51cto.com/attachment/201407/10/907015_1404978005P0lR.png" target="_blank"></a>

填寫名字後下一步,

<a href="http://281816327.blog.51cto.com/attachment/201407/10/907015_1404978007OUuC.png" target="_blank"></a>

選擇“daily”,下一步,

<a href="http://281816327.blog.51cto.com/attachment/201407/10/907015_1404978008ni7p.png" target="_blank"></a>

指定每天運作的時間,下一步。

<a href="http://281816327.blog.51cto.com/attachment/201407/10/907015_1404978008vUDP.png" target="_blank"></a>

指定運作的類型,這裡選擇“Start a Program”,下一步;

<a href="http://281816327.blog.51cto.com/attachment/201407/10/907015_1404978010g8RV.png" target="_blank"></a>

(4)指定運作的腳本(這一步要設定正确,不然腳本會運作出錯),下一步;

Program/script下填寫“Powershell”,表示這個腳本會在powershell環境下運作

Add arguments(optional)填寫腳本絕對路徑名稱

Start in(Optional)填寫腳本所在的檔案夾絕對路徑

<a href="http://281816327.blog.51cto.com/attachment/201407/10/907015_1404978011ebBj.png" target="_blank"></a>

(5)單擊完成;

<a href="http://281816327.blog.51cto.com/attachment/201407/10/907015_1404978015myY7.png" target="_blank"></a>

進行測試:

(1)先檢測Windows更新服務是運作狀态;

<a href="http://281816327.blog.51cto.com/attachment/201407/10/907015_1404978019fgh2.png" target="_blank"></a>

(2)運作一次計劃任務後,看到Windows更新服務是停止狀态,說明計劃任務成功運作了powershell;

<a href="http://281816327.blog.51cto.com/attachment/201407/10/907015_1404978022KZBi.png" target="_blank"></a>

本文轉自 bannerpei 51CTO部落格,原文連結:http://blog.51cto.com/281816327/1436748,如需轉載請自行聯系原作者

繼續閱讀