2013-11-01 61 views
0

有誰知道如何讓我的ps2exe.ps1被執行? 我得到這個例外,並沒有解決它的線索。Powershell甚至無法執行設置執行策略

PS C:\> Set-ExecutionPolicy RemoteSigned 

Execution Policy Change 
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose you to the security risks desc 
about_Execution_Policies help topic. Do you want to change the execution policy? 
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y 
PS C:\> .\ps2exe.ps1 
File C:\ps2exe.ps1 cannot be loaded. The file C:\ps2exe.ps1 is not digitally signed. The script will not execute on the system. Please see "get-help 
At line:1 char:13 
+ .\ps2exe.ps1 <<<< 
    + CategoryInfo   : NotSpecified: (:) [], PSSecurityException 
    + FullyQualifiedErrorId : RuntimeException 
+1

是您在本地創建的腳本還是從互聯網下載的腳本? – poiu2000

+0

根據此頁面從互聯網 –

+0

下載:http://technet.microsoft.com/en-us/library/ee176961.aspx,下載的腳本必須先由受信任的發佈者簽名,然後才能運行。也許你應該暫時將策略設置爲Unrestricted以使該腳本運行 – poiu2000

回答

4

的ExeutionPolicy RemoteSigned允許本地腳本運行(在您的計算機上創建的),並從其他地方簽署的腳本。由於您的腳本是從互聯網下載的,因此它具有與其關聯的「塊」屬性。

要解決此問題,請打開Properties獲取ps1文件,然後單擊UnblockApply/OK

如果您想允許所有內容(不推薦),您可以將執行策略設置爲Unrestricted

值得一提的是,簽名後的腳本會在執行前提示進行確認,除非您已在Trusted Publishers證書存儲區中安裝了特定的發佈者證書。

+1

我不喜歡windows有這麼多奇怪的規則!反正thx! –

+0

這並不奇怪。如果執行遠程文件來自不受信任的來源(不在Internet Explorer的可信站點列表中),Powershell會使用標準Windows規則。由於相同的原因,打開網絡文件會爲您提供運行/取消提示。 :-) –