什麼是Windowspowershell,關於定義可以看百度的解釋http://zh.wikipedia.org/wiki/Windows_PowerShell(或者者http://en.wikipedia.org/wiki/Windows_PowerShell),http://baike.baidu.com/view/1717574.htm,裏面有關於powershell的由來以及使用說明,個人的理解是cmd的服務器版本,與Linux shell通過名字可以直觀感覺兩者應該有很多相似點,都是面向對象開發,兩者用途、使用環境、命令都有近似,但是兩者絕不等同。Windows想把powershell開發成與Linux shell功能相同,但同事的反饋前者還是不如後者。
ps1文檔
讀過http://baike.baidu.com/view/1717574.htm,應該對它有大體瞭解,用途應該很清楚,主要的教程資源比較少。
關於批處理的命令行使用,可以查看http://technet.microsoft.com/zh-cn/library/dd315276.aspx。
簡單的例子
powershell Set-ExecutionPolicy Unrestricted
powershell%.ps1文件路徑%\.ps1文件
powershellSet-ExecutionPolicy Restricted
當沒有powershell Set-ExecutionPolicy Unrestricted這條命令時 ,PowerShell將會獲得以下的提示:File..\..\
.ps1文件 cannot beloaded because the execution of scripts is disabled on this system. Please see” get-help about_signing” for more details.
原因 :Powershell默認的執行權限是受限的,所以我們的函數在啓動的時候沒有被執行。在Powershell中有4種執行權限:
Restricted 默認的設置, 不允許任何script運行
AllSigned 只能運行經過數字證書籤名的script
RemoteSigned 運行本地的script不需要數字簽名,但是運行從網絡上下載的script就必須要有數字簽名
Unrestricted 允許所有的script運行
解決辦法: 用powershell Set-ExecutionPolicy Unrestricted,處理完.ps1文件,主要變回默認執行權限powershellSet-ExecutionPolicy Restricted。這是容易忽略的小問題,應外一個注意的就是要把powershell.exed目錄路徑設置在環境變量中。
最近再用.bat批處理了一些命令,最大的感觸是環境變量和程序的路徑一定要寫清楚,本人遇到的問題就是程序的路徑設置不清楚,導致很多錯誤。忽略過程中的錯誤,用批處理自動執行程序還是有很多好處。